How to increase and decrease the value of a Progress Bar

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Stroumfs
    New Member
    • Mar 2007
    • 28

    How to increase and decrease the value of a Progress Bar

    Hello guys!

    In my form i have a progress bar and two buttons , one plus(+) and one minus(-).
    I want when i press the plus button to increase the progress bar and when i press the minus button to decrease the value of the progress bar.
    I have a timer and i use the mouse_down event. and i want when i press the button the progress bar to perform steps back and forth . how to do this?

    Please help me with some vb code.
    thanks
    Str.
  • CoMPMStR
    New Member
    • Jun 2007
    • 8

    #2
    All you have to do is first make two timers. One for the progress increase and one for the decrease. In the increase timer, put ProgressBar1.va lue = Progressbar1.va lue + 1. In the decrease timer put Progressbar1.va lue = Progressbar1.va lue - 1. Then you need two buttons. In the button for increase, on mouse_down, put IncreaseTimer.e nabled = true and for mouse_up put IncreaseTimer.e nabled = false. In the button for decrease, on mouse_down, put DecreaseTimer.e nabled = true and for mouse_up put Decreasetimer.e nabled = false. Here's an example code. It uses two timers and two buttons. The timer names are timerInc and timerDec, the button names are Button1 and Button2. Button1 is the (-) button and Button2 is the (+) button.

    Code:
        Private Sub timerInc_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerInc.Tick
            ProgressBar1.Value += 1
        End Sub
    
        Private Sub timerDec_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerDec.Tick
            ProgressBar1.Value -= 1
        End Sub
    
        Private Sub Button2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown
            timerInc.Enabled = True
        End Sub
    
        Private Sub Button2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp
            timerInc.Enabled = False
        End Sub
    
        Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
            timerDec.Enabled = True
        End Sub
    
        Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
            timerDec.Enabled = False
        End Sub
    I hope this is what you're looking for. Maybe in the future you can be more specific as to what version of VB you're using.

    Comment

    • Stroumfs
      New Member
      • Mar 2007
      • 28

      #3
      Originally posted by CoMPMStR
      All you have to do is first make two timers. One for the progress increase and one for the decrease. In the increase timer, put ProgressBar1.va lue = Progressbar1.va lue + 1. In the decrease timer put Progressbar1.va lue = Progressbar1.va lue - 1. Then you need two buttons. In the button for increase, on mouse_down, put IncreaseTimer.e nabled = true and for mouse_up put IncreaseTimer.e nabled = false. In the button for decrease, on mouse_down, put DecreaseTimer.e nabled = true and for mouse_up put Decreasetimer.e nabled = false. Here's an example code. It uses two timers and two buttons. The timer names are timerInc and timerDec, the button names are Button1 and Button2. Button1 is the (-) button and Button2 is the (+) button.

      Code:
          Private Sub timerInc_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerInc.Tick
              ProgressBar1.Value += 1
          End Sub
      
          Private Sub timerDec_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerDec.Tick
              ProgressBar1.Value -= 1
          End Sub
      
          Private Sub Button2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown
              timerInc.Enabled = True
          End Sub
      
          Private Sub Button2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp
              timerInc.Enabled = False
          End Sub
      
          Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
              timerDec.Enabled = True
          End Sub
      
          Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
              timerDec.Enabled = False
          End Sub
      I hope this is what you're looking for. Maybe in the future you can be more specific as to what version of VB you're using.
      yes you are very analytical.than ks very much. i am sorry about the version thing.
      thanks a lot

      Comment

      Working...