J
Jerry West
I'm a newbie to .NET from VB6.
I have a Form with a Panel control on it. When the Form loads it maximizes
and so does the Panel control. I then fill an array with the path to images
at a specific folder. At that point a timer fires every x seconds which
calls a routine that draws an image onto the Panel. This works great the
first time the code runs. But each subsquent timer event fails to load a new
image --it is always the same image (which is the first one it loaded). Of
course, I stepped through the code and can clearly see a new image is being
drawn each time after first clearing the old one. Yet, it is always the same
image. Is there something about a Panel that will not load a new image? I
set a watch on the array which references the image to load. When I was
stepping through my code I noticed in the Watch window that on the first run
through the Watch window showed the array value in black text. On the next
run through --and all subsquent ones-- it was in red text. No warnings or
anything it was just in red text. Is that significant? I could find no docs
on what the meaning of this in the Watch window could be. My code is this:
Private Sub DrawTheImage()
Dim Photo As Short
Dim PanelGraphic As Graphics = pnlImage.CreateGraphics
PanelGraphic.Clear(Color.Black)
Try
Photo = RandomNumber(ss.Pics.Count)
Dim newImage As Bitmap =
Bitmap.FromFile(ss.Pics(Photo).FullName)
Dim x As Integer
Dim y As Integer
Dim wid As Integer
Dim hgt As Integer
If (newImage.Height / newImage.Width) > (pnlImage.Height /
pnlImage.Width) Then
' The new image is relatively tall and thin.
' Make the image as tall as possible.
hgt = pnlImage.ClientSize.Height
wid = CInt(hgt * newImage.Width / newImage.Height)
Else
' The new image is relatively short and wide.
' Make the image as wide as possible.
wid = pnlImage.ClientSize.Width
hgt = CInt(wid * newImage.Height / newImage.Width)
End If
x = (pnlImage.Width - wid) \ 2
y = (pnlImage.Height - hgt) \ 2
PanelGraphic.DrawImage(newImage, x, y, wid, hgt)
newImage.Dispose()
PanelGraphic.Dispose()
Catch ex As Exception
'DrawErrorImage()
End Try
End Sub
I have a Form with a Panel control on it. When the Form loads it maximizes
and so does the Panel control. I then fill an array with the path to images
at a specific folder. At that point a timer fires every x seconds which
calls a routine that draws an image onto the Panel. This works great the
first time the code runs. But each subsquent timer event fails to load a new
image --it is always the same image (which is the first one it loaded). Of
course, I stepped through the code and can clearly see a new image is being
drawn each time after first clearing the old one. Yet, it is always the same
image. Is there something about a Panel that will not load a new image? I
set a watch on the array which references the image to load. When I was
stepping through my code I noticed in the Watch window that on the first run
through the Watch window showed the array value in black text. On the next
run through --and all subsquent ones-- it was in red text. No warnings or
anything it was just in red text. Is that significant? I could find no docs
on what the meaning of this in the Watch window could be. My code is this:
Private Sub DrawTheImage()
Dim Photo As Short
Dim PanelGraphic As Graphics = pnlImage.CreateGraphics
PanelGraphic.Clear(Color.Black)
Try
Photo = RandomNumber(ss.Pics.Count)
Dim newImage As Bitmap =
Bitmap.FromFile(ss.Pics(Photo).FullName)
Dim x As Integer
Dim y As Integer
Dim wid As Integer
Dim hgt As Integer
If (newImage.Height / newImage.Width) > (pnlImage.Height /
pnlImage.Width) Then
' The new image is relatively tall and thin.
' Make the image as tall as possible.
hgt = pnlImage.ClientSize.Height
wid = CInt(hgt * newImage.Width / newImage.Height)
Else
' The new image is relatively short and wide.
' Make the image as wide as possible.
wid = pnlImage.ClientSize.Width
hgt = CInt(wid * newImage.Height / newImage.Width)
End If
x = (pnlImage.Width - wid) \ 2
y = (pnlImage.Height - hgt) \ 2
PanelGraphic.DrawImage(newImage, x, y, wid, hgt)
newImage.Dispose()
PanelGraphic.Dispose()
Catch ex As Exception
'DrawErrorImage()
End Try
End Sub