Reload picturebox problem

J

juky

Hi all,

I'm writing a graphic application (for simulation) for pocket pc. I
define a picturebox in my form and build up a special background
using my own math functions. Then I need to draw a line and move it
(based on other math function) in that picturebox, keeping of course
the
special background.

My steps are:
draw the background first and then save in memory
draw the line
clean the picturebox
restore the background from memory
draw the line in new position
etc..


Here my code but doesn't work. The background created is fine, but
it's not reload it inside the loop, I can see it only once.
It is not reloaded within the loop, picturebox shows only the line
moving!

Any idea?

Thanks
Juky

Private Sub Simulation()
Dim bitcopy As Bitmap
bitcopy = New Bitmap(Me.PictureBox.Width,
Me.PictureBox.Height)

Me.PictureBox.Image = New Bitmap(Me.PictureBox.Width,
Me.PictureBox.Height)
Dim g As Graphics = Graphics.FromImage(Me.PictureBox.Image)

g.Clear(Color.White)


'DrawBackground with math functions
....
g.DrawLine(Color.Blue, x0,x1,x1,y1)
.....

PictureBox.Refresh()

'save my background
bitcopy = Me.PictureBox.Image

For i = 0 To norm
x0=....
y0=....
x1=....
y1=....

g.DrawLine(blackPen, x0,x1,x1,y1)
PictureBox.Refresh()

g.Clear(Color.White)

'reload background
g.DrawImage(bitcopy, 0, 0)

PictureBox.Refresh()
Next
End Sub
 

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

Top