Form doesn't remember what's drawn on it?

  • Thread starter Thread starter Noozer
  • Start date Start date
N

Noozer

If I draw on a form, then place another form on top of it, all the drawings
on the first form are erased. VB.Net doesn't have an AutoRedraw function.

How do I get graphics on a form to persist?
 
Where are you drawing? If you put it in OnPaint, it should repaint whatever
you draw
 
I'm drawing based on events... The display could be empty for hours or fill
up within minutes, all depending on whether or not other controls generate
certain events.
 
* "Noozer said:
If I draw on a form, then place another form on top of it, all the drawings
on the first form are erased. VB.Net doesn't have an AutoRedraw function.

Create a 'Bitmap' of appropriate size, then obtain a 'Graphics' object
for the bitmap using 'Graphics.FromImage', draw onto the bitmap and
paint the bitmap onto the form in its 'Paint' event handler.
 
Noozer,
In addition to Herfried's comments.

When using the bitmap as Herfried suggested I normally resize the bitmap in
the Resize event (read create a new bitmap). Of course this can cause you to
loose the existing bitmap. You can either draw the existing onto the new
one, or simply allow a "blank" slate to be used.

Alternatively rather then "drawing on the form" I will store the information
that needs to be drawn in an object model, then in the Paint event (OnPaint
method) I call methods within this object model that cause it to be drawn.
This separates your data from the presentation, also if done carefully
enough allows you to present the info on the screen, a printer, or a bitmap.
The bitmap can then be stored in a database, sent over the internet, saved
in a file...

Of course this object model I can save to be reloaded later...

Hope this helps
Jay
 
Back
Top