painting and refreshing

  • Thread starter Thread starter Nikola Bucic
  • Start date Start date
N

Nikola Bucic

I have a problem with picturebox. I'm drawing on it with
picturebox.DrawString, picturebox.DrawRectangle, etc. and it's working
fine. But when I open another window over it I lost that. Triggering
picturebox.Invoke() or picturebox.Refresh() clears picture box.

How to solve problem of clearing picture box? I want image (it is
drawing actually) to be in picture box.

tnx in advance
 
How to solve problem of clearing picture box? I want image (it is
drawing actually) to be in picture box.

You should be drawing into the picturebox from its Paint event; if it's
not getting redrawn, then you probably aren't. If you put the redraw
code in the Paint event, it will automatically be called when the
graphics need redrawing, e.g. after being 'wiped' over by another
window.
 
Create a bitmap the size of the picture box to hold your drawing:

Bitmap bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
pictureBox.Image = bitmap;

Make drawing changes on the bitmap:
Graphics bitmapGraphics = Graphics.FromImage(bitmap);
bitmapGraphics.DrawString(...);

Whenever you change the bitmap, invalidate the picture box so it will
be repainted:
pictureBox.Invalidate();
 
is there possibility to use double buffer method? one buffer for on
screen and one buffer for reloadinh or refreshing
 
That's what you have: one copy of the drawing in video memory and one
copy in the bitmap.
 
Back
Top