I'm really a novice and I'm trying to draw a thermometer that moves up or down with temp change. I created a second form on my project for the thermometer and access it using Thermometer.Showdialog(().
Then on the thermometer form, I'm using this code:
Private Sub ThermometerForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim g As Graphics = e.Graphics
Dim TimeNow As Date
Dim TimeLater As Date
Dim intWaitTime As Integer = 1
TimeNow = DateTime.Now
TimeLater = DateTime.Now
intWaitTime = 1 'number of seconds each
For t = 1 To 33
TimeNow = DateTime.Now
TimeLater = DateTime.Now
'Draw column of thermometer in blue
g.DrawRectangle(Pens.Blue, 410, 40, 10, 350)
'e.Graphics.DrawRectangle(Pens.Blue, 410, 40, 10, 350)
'Draw bulb of thermometer in blue
g.DrawEllipse(Pens.Blue, 400, 375, 30, 30)
'Fill shapes after outline, so fill covers parts _
'of shapes
'Fill column of thermometer with red
g.FillRectangle(Brushes.Red, 411, intFillTop, 8, intFillHeight)
'e.Graphics.FillRectangle(Brushes.Red, 411, 41, 8, 348)
'Fill bulb of thermometer with red
e.Graphics.FillEllipse(Brushes.Red, 401, 376, 28, 28)
intFillTop = intFillTop - 10
intFillHeight = intFillHeight + 10
'Time Delay
Do
TimeLater = DateTime.Now
Application.DoEvents()
Loop Until DateDiff(DateInterval.Second, TimeNow, TimeLater) >= _
intWaitTime
Next
End Sub
It works great and shows the red moving up though the rectangle. Problem is that when it's finished the loop (33 seconds) and I click anywhere on the form it apparently enters the loop again, then hangs so I have to manually close it from Windows.
There are no other objects on the form.