Why does graphics disappear

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi There,

If I switch from the Form i have drwan my graphics like Rectangle to some
other Window and come back to my graphic window the drawing is disappeared.

How should I go abt it? Can if u can explain me why it happens also it'll be
gr8.

:)

Regards
Rohan
 
Rohan said:
If I switch from the Form i have drwan my graphics like Rectangle to some
other Window and come back to my graphic window the drawing is
disappeared.

Handle the form's 'Paint' event or override its 'OnPaint' method and draw
the rectangles there ('e.Graphics.Draw*'). The form must be repainted every
time its contents are overlapped by another window.
 
In addition to Herfried's'answer you can also draw your stuff on a bitmap
and set it as the forms backgroundimage.
For example:

Dim myBitmap As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
Dim g As Graphics
g = Graphics.FromImage(myBitmap)
g.FillRectangle(Brushes.Brown, 0, 0, myBitmap.Width, myBitmap.Height)
g.FillEllipse(Brushes.BlueViolet, 0, 0, myBitmap.Width, myBitmap.Height)
g.Dispose()
Me.BackgroundImage = myBitmap

Ofcourse if the size of your form can change you'll have to catch that event
and redraw everything if you want your bitmap to have the same size as your
form.

Drawing on bitmap for example can be handy when you want to create your own
drawing in a picturebox and don't want to redraw everything every time the
paint event fires.

Hth Greetz Peter
 
Private m_BufferBitmap As Bitmap
Private m_BufferGraphics As Graphics

OnLoad **************
m_BufferBitmap = New Bitmap(Me.Size.Width, Me.Size.Height,
Me.CreateGraphics())
m_BufferGraphics = Graphics.FromImage(m_BufferBitmap)

' Clear the new bitmap.
m_BufferGraphics.Clear(Me.BackColor)
*********************

Note: Drawing in the surface should be using m_BufferGraphics object..

On Paint ***************
If Not (m_BufferBitmap Is Nothing) Then e.Graphics.DrawImage(m_BufferBitmap,
0, 0)
**********************

Thanks for the direction Herfried

Regards
Rohan
 

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

Back
Top