I'm trying to make a form with a thermometer painted on it. I want the thermometer to go up each second. I tried the code below and it sorta works, but not really. It does the For... Next loop okay and shows the message box, but then does NOT Exit Sub or Me.Close. Instead it starts the For... Next loop again. When it finishes the For... Next loop the second time it shows the message box again, then appears to stop executing, but still does not Me.Close. I guess I don't understand the paint event.
Public Class ThermometerForm
Public intFillTop As Integer = 361
Public intFillHeight As Integer = 28
Private Sub ThermometerForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim TimeNow As Date
Dim TimeLater As Date
Dim intWaitTime As Integer = 1 'number of seconds each
TimeNow = DateTime.Now
TimeLater = DateTime.Now
'Draw column of thermometer in blue
e.Graphics.DrawRectangle(Pens.Blue, 410, 40, 10, 350)
'e.Graphics.DrawRectangle(Pens.Blue, 410, 40, 10, 350)
'Draw bulb of thermometer in blue
e.Graphics.DrawEllipse(Pens.Blue, 400, 375, 30, 30)
'Fill bulb of thermometer with red
e.Graphics.FillEllipse(Brushes.Red, 401, 376, 28, 28)
'Dim mp As Integer = intMeltingPoint / 10
'Dim intCurrentTemp As Integer = 0
'Make thermometer go up each second
For t = 1 To 18 'mp '105
TimeNow = DateTime.Now
TimeLater = DateTime.Now
'Put current temp into label
'intCurrentTemp = t * 10
'lblTemp.Text = "Current sample temperature: " & intCurrentTemp
'Fill shapes after outline, so fill covers parts of shapes
'Fill column of thermometer with red
e.Graphics.FillRectangle(Brushes.Red, 411, intFillTop, 8, intFillHeight)
'e.Graphics.FillRectangle(Brushes.Red, 411, 41, 8, 348)
intFillTop = intFillTop - 3 '10
intFillHeight = intFillHeight + 3 '10
'Time Delay
Do
TimeLater = DateTime.Now
Application.DoEvents()
Loop Until DateDiff(DateInterval.Second, TimeNow, TimeLater) >= _
intWaitTime
Next t
MessageBox.Show("Close form")
Exit Sub
Me.Close()
End Sub
End Class