Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
'System.EventArgs' does not contain a definition for 'Graphics' and no extension method 'Graphics' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?).

this error was occured when i was using graphics in button click event

please help me with this error

my requirement: when i click the button some graphics(eg: ellipse) should be drawn
Thnk you.

What I have tried:

private void btnsadsmile_Click(object sender, EventArgs e)
{
Graphics g = e.Graphics;// here the error occurs no definition for graphics
Pen p = new Pen(Color.RosyBrown, width: 3);
int w = this.ClientSize.Width;
int h = this.ClientSize.Height;
g.DrawEllipse(p, w / 3 + 67, h / 3 + 50, 20, 10);
}
Posted
Updated 18-Nov-16 20:25pm
v2

Obviously that property does not exist, you can create a Graphics object with : How to: Create Graphics Objects for Drawing[^]
 
Share this answer
 
Click events do not have anything to do with drawing: as a result they do not provide a Graphics context. Only Paint events do that for you.
Besides, if it did provide such a context, it would logically be a context which allows you to draw on the Button (or other control) which the use clicked, not the whole form.

Do your actual drawing in the Paint event handler and get that signaled by calling Invalidate fit the form of Panel you want to draw onto.
 
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