Question

i am creating a drawing programe which Suppose to take the parameters from the user (Radius,height,width,....etc) i have created a class with one paramter (radius)

public int faceoutline(int r)
    {
        Graphic = pictureBox1.CreateGraphics();
        Graphic.DrawEllipse(myPen, 0, 0, r, r);
        return r;
    }

then i call it :

private void button1_Click(object sender, EventArgs e)
    {
        faceoutline(int.Parse(textBox1.Text));
        pictureBox1.Invalidate();
    }

....and nothing happens i copied the button code to a timer but it keep balnking WHAT I AM DOING WRONG ?!

Était-ce utile?

La solution

You should place the drawing code in the Paint event handler of the PictureBox, and use the Graphics provided in the event args. This way, your custom drawing code will be executed every time the control is redrawn.

If you don't do it this way, anything you draw will disappear the next time the control is redrawn. In your code, you call Invalidate right after you draw your ellipse, so the control is redrawn without the ellipse...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top