hi all
i want to make a temperature gauge using scroll bar (pls refer to Attachments)
it has label to show the text of current temperature and if you are noticed the are also two labels in blue and red which indicates coolness or hotness.the problem is when the temperature reached certain point for example 50 Celsius,the color label is not working.i mean initially i set red label,visible = true thus make blue label visible and it indicates the temperature is still cool but when scroll it to 50 Celsius,the red label is not shown up and blue label is still there.also not working when i decrease the temperature less than 50 Celsius.

here is the code

Public Class Form1
    Inherits System.Windows.Forms.Form

Private Sub vsbCount_Change(ByVal newScrollValue As Integer)
        lblCount.Text = CStr(newScrollValue)
    End Sub
  Private Sub vsbCount_Scroll(ByVal sender As System.Object, ByVal eventArgs As System.Windows.Forms.ScrollEventArgs) Handles vsbCount.Scroll
        Dim vsbCount As Integer

        Select Case eventArgs.Type
            Case System.Windows.Forms.ScrollEventType.EndScroll
                vsbCount_Change(eventArgs.NewValue)
        End Select

        If vsbCount < 50 Then
            lblBlue.Visible = True
            lblRed.Visible = False


        ElseIf vsbCount < 100 Then
            lblRed.Visible = True
            lblBlue.Visible = False
        End If


       
    End Sub
End Class
Attachments 1.jpg 69.31 KB

Try changing these:

ElseIf vsbCount > 50 Then
lblRed.Visible = True
lblBlue.Visible = False

Edited 6 Years Ago by Bodul: n/a

This works for me, but there is better way to do this than using lblCount.text.

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub vsbCount_Change(ByVal newScrollValue As Integer)
        lblCount.Text = CStr(newScrollValue)
    End Sub
    Private Sub vsbCount_Scroll(ByVal sender As System.Object, ByVal eventArgs As System.Windows.Forms.ScrollEventArgs) Handles vsbCount.Scroll
        
        Select Case eventArgs.Type
            Case System.Windows.Forms.ScrollEventType.EndScroll
                vsbCount_Change(eventArgs.NewValue)
        End Select

        If lblcount.Text < 50 Then
            lblblue.Visible = True
            lblred.Visible = False


        ElseIf lblcount.Text < 100 Then
            lblred.Visible = True
            lblblue.Visible = False
        End If
    End Sub


    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        lblcount.Text = 0
    End Sub
End Class
Comments
very good explanation indeed

OMG Bodul.
its works perfectly!!!!
u make my day :)
really thanks :)

Ok this is much better:

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub vsbCount_Change(ByVal newScrollValue As Integer)
        lblcount.Text = CStr(newScrollValue)

        If newScrollValue < 50 Then
            lblblue.Visible = True
            lblred.Visible = False


        ElseIf newScrollValue < 100 Then
            lblred.Visible = True
            lblblue.Visible = False
        End If
    End Sub
    Private Sub vsbCount_Scroll(ByVal sender As System.Object, ByVal eventArgs As System.Windows.Forms.ScrollEventArgs) Handles vsbCount.Scroll

        Select Case eventArgs.Type
            Case System.Windows.Forms.ScrollEventType.ThumbTrack
                vsbCount_Change(eventArgs.NewValue)

            Case System.Windows.Forms.ScrollEventType.SmallIncrement
                vsbCount_Change(eventArgs.NewValue)

            Case System.Windows.Forms.ScrollEventType.SmallDecrement
                vsbCount_Change(eventArgs.NewValue)

            Case System.Windows.Forms.ScrollEventType.EndScroll
                vsbCount_Change(eventArgs.NewValue)


        End Select

    End Sub

Now you can move that slider however you want and it should work. Not using that lblCount anymore.

There is still room for improvement but I have to continue my work :)

Edited 6 Years Ago by Bodul: n/a

This article has been dead for over six months. Start a new discussion instead.