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
                TimeLater = DateTime.Now
            Loop Until DateDiff(DateInterval.Second, TimeNow, TimeLater) >= _

    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.

7 Years
Discussion Span
Last Post by OldQBasicer

Hello OldQ,

I don't have a lot of experiance with graphics, but I think the problem is you put this in the paint event. Every time you click, it has to re-paint. Is there a reason you can't put this code in a button click event? Or, if you just intend to run it once, from the form_open event? Then it would run and stop after the 33 seconds.

This sounds very cool - how do you feed the temperature into the application?


Thanks for that... I'll try getting the code out of the paint event. It never occurred to me that I didn't have to put it in the paint event.

It's part of a lab simulation my chemistry students are going to do. They're heating water from 20 degrees and they're going to chose how hot they want it. I'm getting their input from the main form.

Thanks again...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.