Today, I saw a problem with C # graphic processing. I don't know why, or does it exist.
Design Interface
Background code:
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. LINQ;
Using system. text;
Using system. Windows. forms;
Namespace graphic_processing
{
Public partial class drawline: Form
{
Public drawline ()
{
Initializecomponent ();
}
Private void drawline_load (Object sender, eventargs E)
{
Pen redpen = new pen (color. Red, 10 );
Point P1 = new point (10, 50 );
Point P2 = new point (10,200 );
Graphics G = This. creategraphics ();
G. drawline (redpen, P1, P2 );
}
Private void button#click (Object sender, eventargs E)
{
Pen redpen = new pen (color. Black, 10 );
Point P1 = new point (10, 50 );
Point P2 = new point (200, 50 );
Graphics G = This. creategraphics ();
G. drawline (redpen, P1, P2 );
}
Let's guess what will happen,
When the program is loaded:
When the button is clicked
Why is there such a problem? I really don't know. Curious. If any master knows, please tell me the reason.
I thought about the result of the screen weight painting, and I re-painted the original image.
If you write the code like this, there will be no errors.
Private void drawline_paint (Object sender, eventargs E)
{
Pen redpen = new pen (color. Red, 10 );
Point P1 = new point (10, 50 );
Point P2 = new point (10,200 );
Graphics G = This. creategraphics ();
G. drawline (redpen, P1, P2 );
}