Why is the drawing not executed when winform is loaded?

Source: Internet
Author: User

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 );
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.