Visual Studio, Would like to add a progress bar that I control the time.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ReneWilson
    New Member
    • Sep 2013
    • 1

    Visual Studio, Would like to add a progress bar that I control the time.

    Ok, not sure if this is the right place to ask, but here goes... oh yeah, first time poster, can I get a whoop whoop.

    Im a newbie and am still learning, but heres what kind of code Im looking for:
    In Visual Studio, Im looking to create a Indeterminate Progress Bar and I want to figure out what code I could use. The twist is, I have created a form and I want to enter a number (in minutes) on my form and then the progress bar increments to 100% in that time limit that I entered.

    Sorry if this is as clear as muddy water. Any help would be appreciated.
  • txc2004
    New Member
    • Oct 2013
    • 2

    #2
    Hello!

    Hear is one simple code and easy to learn from this.

    Add in your form:
    one label
    one progressbar
    one texbox
    one button

    and put this code:

    Code:
    Public Class Form1
    Dim ellapsedminutes As Integer = 0
    Dim ellapsedseconds As Integer = 0
    
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    ProgressBar1.Minimum = 0
    ProgressBar1.Maximum = TextBox1.Text * 60
    
    ellapsedseconds = ellapsedseconds + 1
    If ellapsedseconds > 59 Then ellapsedminutes = ellapsedminutes + 1 : ellapsedseconds = 0
    ProgressBar1.Value = ellapsedseconds
    
    Label1.Text = ellapsedminutes & " min " & ellapsedseconds & " sec"
    
    If ellapsedminutes = TextBox1.Text Then
    Timer1.Enabled = False
    Label1.Text = "Finish"
    
    ' put hear everything else u like to do at the end
    
    End If
    
    End Sub
    
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    TextBox1.Text = 1
    
    Timer1.Interval = 1000
    Timer1.Enabled = True
    End Sub
    
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    'reset all and start from the begining
    ellapsedminutes = 0
    ellapsedseconds = 0
    ProgressBar1.Value = 0
    Label1.Text = ellapsedminutes & " min " & ellapsedseconds & " sec"
    Timer1.Enabled = True
    End Sub
    
    End Class

    Comment

    Working...