Home > Net >  Help: drawing shows need to button according to the two questions
Help: drawing shows need to button according to the two questions

Time:10-14

Simple example: put two identical in form and overlap of the Panel controls, there is a PictureBox Panel1 controls, began to show Panel2, Panel1 does not display, press the button button, drawing on the PictureBox, code is as follows:
The two problems: you push the button to show the painting line, why can't press the button shows?
Private void button1_Click (object sender, EventArgs e)
{
Panel2. Visible=false;
Panel1. Visible=true;
//panel1. BringToFront ();
Graphics g=pictureBox1. CreateGraphics ();
Pen p=new Pen (Color. Red, 1);
G.D rawLine (p, 10, 50, 200, 100);
Conviction yourself ispose ();
G.D ispose ();

}

Private void pictureBox1_Paint (object sender, PaintEventArgs e)
{
Graphics g=pictureBox1. CreateGraphics ();
Pen p=new Pen (Color. Red, 1);
G.D rawLine (p, 10, 50, 200, 100);
Conviction yourself ispose ();
G.D ispose ();
}

CodePudding user response:

Why CreateGraphics, you create the object scope will fail, the content of the drawing is not ah, is not to save images,

Don't know at the waste materials
,

Interface for drawing in the Paint event PaintEventArgs Graphics, refresh called when control is invalid

CodePudding user response:

To solve the,
  •  Tags:  
  • C#
  • Related