|
-
Aug 25th, 2010, 09:02 AM
#4
Re: How do you draw on a picturebox outside of the pain event.
 Originally Posted by Jenner
Painting on a picturebox is an ugly way to do things these days. If you need to do such things, it's easier to just paint on the form itself.
That's not necessarily true. A PictureBox is optimised for GDI+ and can provide smoother transitions.
The general principle of GDI+ is very simple:
1. You store the data that describes the drawing in member variables.
2. You handle the Paint event, read the data from those member variables and use the Graphics object provided to perform the drawing.
3. Whenever you want to change the drawing you update the member variables and then call Invalidate and Update or Refresh on the control.
That's all there is to it, besides the detail of exactly what Graphics methods to call. If you want an example then follow the CodeBank link in my signature and check out my Simple Drawing thread. You'll see there that, each time the user draws a line, the data representing that line is added to a member variable containing all the lines, Invalidate is called to specify what area of the control has changed and Update is called to raise the Paint event. The actual drawing is then done in the Paint event handler. That same principle should be employed no matter what you're drawing.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|