How to make colordialog appear?

82 Views Asked by At

I am simply trying to make a colordialog appear, using the following code as a test out/practise assignment.

{
            Point puntA = new Point(10, 300);
            Point puntB = new Point(90, 200);
         
            Pen tekenpotlood = new Pen(colorDialog1.Color , 4);

            Graphics papier = pictureBox1.CreateGraphics();

            papier.DrawLine(tekenpotlood, puntA, puntB);

}

I have dragged a colordialog onto the form, I have also added the code menntioned in the textbook (with or without erasing colordialog)

any help is appreaciated with this problem..

1

There are 1 best solutions below

1
On

Thanks a lot for the answer, Classes is the next chapter of the course, but i got it to work, with some changes.

here is the code now functioning:

public partial class Form1 : Form
{
    ColorDialog colorDialog;

    public Form1()
    {
        colorDialog = new ColorDialog();
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
       





    Pen pen = new Pen(colorDialog.Color, 4);
    Point puntA = new Point(10, 300);
    Point puntB = new Point(90, 200);
    
    if (colorDialog.ShowDialog() == DialogResult.OK)
    {
       

    Graphics papier = pictureBox1.CreateGraphics();

    papier.DrawLine(pen, puntA, puntB);
    }

        else
        {
            // The user cancelled the dialog
        }


    }
}

}