0

I have a problem: my application needs to draw some images on panels.

I make it on Paint(..) event.

But if I move application window then form and all controls will repaint.

How can I get away from it? May be I should change event for paiting? I have tried to draw into Load(..) event, but application nothing draw into panels in this way.

rene
  • 41,474
  • 78
  • 114
  • 152
user1134602
  • 597
  • 1
  • 4
  • 11

2 Answers2

0

You can not get rid of Repaint() as this is fundamental OS function.

IMO, you are concerned about flipping after resize. To resolve this, you can do like in my answer.

You can use PictureBoxes instead of drawing them and, by the way, do not forget to enable double buffering

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
Tigran
  • 61,654
  • 8
  • 86
  • 123
0

Only parts used are drawn by the application. Therefore, whenever parts not previously visible are uncovered (by moving that window or windows above it, or resizing, minimizing/maximizing etc.) the missing parts need to be redrawn, which is what you're seeing.

If you cannot just redraw the parts, you can for instance use a bitmap and a PictureBox to cache the drawn data so that redrawing the window only requires the bitmap to be transferred to the screen without actually redrawing the contents of the bitmap.

In that case you draw your stuff to the bitmap canvas instead of the form canvas.

Lucero
  • 59,176
  • 9
  • 122
  • 152
  • Please, tell me, how should I draw on canvas and set it for PictureBox or Panel? – user1134602 Jan 08 '12 at 11:35
  • Create a `Bitmap`, create a `Graphics` object on that bitmap, draw on it, assign the bitmap to the `PictureBox`. Don't forget to properly dispose the `Graphics` object (best done with a `using` statement). – Lucero Jan 08 '12 at 11:37
  • 1 thing - how can I create Graphics object for Bitmap? – user1134602 Jan 08 '12 at 12:09
  • @user1134602, the graphics object has static methods for that: `Graphics.FromImage(bitmap)` – Lucero Jan 08 '12 at 14:24