I use multiple panels and draw graphics on them.
Sometimes I need to add some changes to the graphics.
When I clear the panel and redraw everything inside - it works, but causes a flickering effect because all elements actually disappear and are created again.
Here is an example:
private void drawStatus() {
Panel Panel1 = new Panel();
Panel1.Width = 100;
Panel1.Height = 100;
Panel1.Location = new System.Drawing.Point(0, 0);
Panel1.Visible = true;
Panel1.Paint += new PaintEventHandler(Panel1Paint);
panelDashboard.Controls.Add(Panel1);
}
private void Panel1Paint(object sender, PaintEventArgs e) {
var g = e.Graphics;
Pen PenGray = new Pen(Color.Gray, 1F);
g.DrawRectangle(PenGray, SharedData.X, SharedData.Y, SharedData.W, SharedData.H);
PenGray.Dispose();
g.Dispose();
}
My thoughts are that I should fire PaintEventHandler
again.
Panel1.Refresh()
works for me, handler fires again, but it clears all panel content.
The question is, is it possible to fire the PaintEventHandler
again without clearing the existing contents of the panel?
Or maybe there is another way to draw on the panel again.