D
D
Denis2021-04-10 20:02:02
C++ / C#
Denis, 2021-04-10 20:02:02

How can I clear the Panel of what I've drawn without erasing the background image?

Panel.Invalidate();Does not help. Because I'm redrawing multiple times per second and it's redrawing when the key is released.
Panel.Clear(Color.Teal);Does not help. Draws the entire screen . Doesn't help. Same as the point above. Draws the screen, and the background image. Helps, but also redraws the background image. What should I do?
Panel.Clear(Color.FromArgb(255));
Panel.Refresh();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2021-04-12
@petermzg

You place the background image in a bitmap and, when redrawing from it, draw it on the control canvas. Draw only what you need:

protected override void OnPaint(PaintEventArgs e)
{
     base.OnPaint(e);
     var g = e.Graphics;
     var clipRect = e.ClipRectangle;
     ...
}

It is also better to draw first on a separate bitmap from which everything is transferred to the control canvas. (double buffering)
Try and erase only that part of the control that has really changed.
Invalidate(Rectangle.Round(rect));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question