Click here to Skip to main content
15,889,876 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello, i want when i click on button1 draw a ellipse on paint of picturebox1.
Posted

You can do it, but it simply makes little to no sense. This is the same as drawing on a bitmap, but with extra hassles which won't give you anything good. Doing such thing is easy enough, only don't use PictureBox, it does not have such purpose, only helpful if you need static images. Please see my past answers:
Append a picture within picturebox[^],
draw a rectangle in C#[^],
How do I clear a panel from old drawing[^].

See also:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].

—SA
 
Share this answer
 
Handle the Paint event, and draw an ellipse on the supplied Graphics object:

C#
private bool drawIt = false;
private void myButton_Click(object sender, EventArgs e)
    {
    drawIt = !drawIt;
    myPictureBox.Invalidate();
    }

private void myPictureBox_Paint(object sender, PaintEventArgs e)
    {
    if (drawIt)
        {
        e.Graphics.DrawEllipse(Pens.Red, 10, 10, myPictureBox.Width - 20, myPictureBox.Height - 20);
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900