In a c#winform application, you can draw lines or graphics with GDI.
1. Draw lines or graphics on the main form
using (Graphics g = this. CreateGraphics ())
{
G.drawline (Pens.blue, New Point (Ten), New Point (100, 100));
}
2. Draw a line or graphic on a specified container, such as on a Panel1
using (Graphics g = this.panel1.CreateGraphics ())
{
G.drawline (Pens.blue, New Point (Ten), New Point (100, 100));
}
However, when you want to clear all the lines or graphics that are drawn by GDI in the current form, you can clear them in the following way.
Graphics g= this.pic_Img.CreateGraphics ();
G.clear (This.pic_Img.BackColor);
G.dispose ();//Release resources
The G.clear () function refers to redrawing the background of the form with the specified color, and the parameter in the Clear function is the color to be drawn when the parameter is set to this. When BackColor, which is the background color of the current form, you can clear all the lines or graphics drawn from GDI in the current form.
C # WinForm How to clear all lines or graphics drawn by the graphics class