Form looses graphics after loosing focus

V

Vasilis X

Hello.
I am using vb.net.

On a form i have a picture box and i draw points, lines, arcs etc in it.

When i minimize the form and then maximize it again or if the form looses
the focus for any reason
all graphics are gone and i have to redraw them.

Is there a way to make my application to display the graphics all the time?

Thank you
Vasilis
 
K

Ken Tucker [MVP]

Hi,

I would either draw on the picturebox in its paint event or draw on
a bitmap and set the pictureboxes image to the bitmap.

Dim bm As New Bitmap(PictureBox1.Width, PictureBox1.Height)
Dim g As Graphics = Graphics.FromImage(bm)

' clear the image with controls background color
g.Clear(SystemColors.Control)

g.DrawLine(Pens.Red, 5, 5, 25, 25)
g.FillEllipse(Brushes.Blue, 30, 10, 10, 10)

PictureBox1.Image = bm
g.Dispose()


Ken
 
C

Chris Dunaway

The simple answer is that a PictureBox is designed to show and image.
It is not meant to be a canvas on which to draw things. Check out this
article which should give you some ideas:

http://www.bobpowell.net/picturebox.htm

Much of the code is in C# but I think there is some VB there too. You
should be able to figure out what is going on though.
 

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

Similar Threads


Top