471,321 Members | 1,704 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,321 software developers and data experts.

painting and refreshing

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

Jan 9 '06 #1
4 1731
> 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.

Jan 9 '06 #2
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();

Jan 9 '06 #3
is there possibility to use double buffer method? one buffer for on
screen and one buffer for reloadinh or refreshing

Jan 9 '06 #4
That's what you have: one copy of the drawing in video memory and one
copy in the bitmap.

Jan 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Harry_Crow | last post: by
5 posts views Thread by Alien | last post: by
3 posts views Thread by Shravan Kumar | last post: by
2 posts views Thread by Robert Misiak | last post: by
4 posts views Thread by Dafü | last post: by
2 posts views Thread by Carl Gilbert | last post: by
7 posts views Thread by adh | last post: by
reply views Thread by J Rico | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.