keeping objects on redrawing

brane84

New member
Joined
Jul 31, 2006
Messages
2
Programming Experience
1-3
Hi !!
I'm a student with some experience on the drawing in Delphi 2005 and VB.NET. My curent project is to make something that would look like Microsoft Paint. My main problem is redrawing, drawing ghost images. For example if I constantly redraw on mousemove events to show the dimensions of new object I wil lose any previous objects drawn on the surface. Can someone give me any kind of help? It does not have to be a solution, just a some kind of global explanation of how could it be done (redrawing a form and not loosing drawn objects). I could also use some hyperlink if someone could direct me.
Cheers!
 
You could save what's been drawn to a global image and just start your redraw by drawing the image.
 
ALL GDI+ drawing should be done on the Paint event of the control on which you're drawing. The reason you're losing your drawing is because the control keeps getting repainted. By drawing on the Paint event you redraw your drawing every time the control is repainted. The proper way to do GDI+ drawing is to set up the parameters for the drawing in class-level variables then tell the control to repaint. In the Paint event handler you read the parameters and do the drawing. To force the control to repaint you can call its Refresh or Invalidate method. Refresh will redraw the entire control. This is often inefficient so you should call Invalidate and specify the region that requires repainting.

Let's say that you want the user to be able to draw lines, circles and rectangles on the screen. You should declare three collections to store the shapes; one for lines, one for circles and one for rectangles. You then read each of those collections in the Paint event handler and draw the shapes. If you want the user to be able to creat a shape by clicking and dragging then each time the dimensions of the shape change you need to edit the appropriate variables and then Invalidate the smallest possible region of the control that contained both the old shape and the new shape, so that the old shape is erased and the new one drawn.

You should read some GDI+ tutorials.
 
Back
Top