Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C# drawing program has two questions that I hope experts can answer: 1. After the new drawing was created, the screen was cleared, and when drawing again, the previously cleared drawing reappeared.

C# drawing program has two questions that I hope experts can answer: 1. After the new drawing was created, the screen was cleared, and when drawing again, the previously cleared drawing reappeared.

C# drawing program has two questions that I hope experts can answer: 1. After the new drawing was created, the screen was cleared, and when drawing again, the previously cleared drawing reappeared.

This way

You don’t clear the graphics in the new menuitemclick

You clear it in the paint event of the picturebox

You set a flag, for example, bool creatNew = false;

private void create new ToolStripMenuItem_Click(object sender, EventArgs e)

{

createNew= true;

< p> pictureBox1.Refresh();

}

Inside the paint event

if(createNew)

{

< p> e.Graphics.Clear();

}

It is best to draw in the paint event

In addition, when you clear the picture Your line[k, 2] elements that store line data must be cleared, otherwise they will still be drawn.

It is best to use a List or Queue to store the elements you want to draw. Then clear the paint event first, and then draw everything in it

Second question

You'd better define the line class

Including starting coordinates, end coordinates, and color

The line class can inherit the shape class, so that if you want to expand the drawing function in the future, you can do the same

Do not use public *** Brush, if you use a public brush, if you change one color, of course, all colors will change