I have read somewhere that CreateGraphics()
will do this steps for us :
I have my code like this :
private void Form1_Load(object sender, EventArgs e)
{
grFrom = this.CreateGraphics();
grFrom.FillRectangle(Brushes.Red, this.ClientRectangle);
}
There is no red rectangle...but, When I copy line below in Form1_paint
, every thing runs correctly.
grFrom.FillRectangle(Brushes.Red, this.ClientRectangle);
So Question is Here:
What is the e.Graphics
in Form1_paint
?
CreateGraphics
or e.Graphics
?
The Paint event is raised when the control is redrawn. It passes an instance of PaintEventArgs to the method(s) that handles the Paint event. When creating a new custom control or an inherited control with a different visual appearance, you must provide code to render the control by overriding the OnPaint method.
Parameter: This function accepts three parameters as mentioned above and described below: w: It is a number that sets the width of the off-screen graphics buffer.
Drawing in C# is achieved using the Graphics Object. The Graphics Object takes much of the pain out of graphics drawing by abstracting away all the problems of dealing with different display devices and screens resolutions. The C# programmer merely needs to create a Graphic Object and tell it what and where to draw.
Two things:
Dispose()
prior to exiting. You should put your statement inside of a using block.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With