painting and refreshing

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
 
P

Paul Henderson

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.
 
K

kevin cline

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();
 
N

Nikola Bucic

is there possibility to use double buffer method? one buffer for on
screen and one buffer for reloadinh or refreshing
 
K

kevin cline

That's what you have: one copy of the drawing in video memory and one
copy in the bitmap.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top