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,