By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,899 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,899 IT Pros & Developers. It's quick & easy.

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

P: 1
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.
Sep 18 '13 #1
Share this Question
Share on Google+
1 Reply


P: 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:

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2. Dim ellapsedminutes As Integer = 0
  3. Dim ellapsedseconds As Integer = 0
  4.  
  5. Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  6. ProgressBar1.Minimum = 0
  7. ProgressBar1.Maximum = TextBox1.Text * 60
  8.  
  9. ellapsedseconds = ellapsedseconds + 1
  10. If ellapsedseconds > 59 Then ellapsedminutes = ellapsedminutes + 1 : ellapsedseconds = 0
  11. ProgressBar1.Value = ellapsedseconds
  12.  
  13. Label1.Text = ellapsedminutes & " min " & ellapsedseconds & " sec"
  14.  
  15. If ellapsedminutes = TextBox1.Text Then
  16. Timer1.Enabled = False
  17. Label1.Text = "Finish"
  18.  
  19. ' put hear everything else u like to do at the end
  20.  
  21. End If
  22.  
  23. End Sub
  24.  
  25. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  26. TextBox1.Text = 1
  27.  
  28. Timer1.Interval = 1000
  29. Timer1.Enabled = True
  30. End Sub
  31.  
  32. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  33. 'reset all and start from the begining
  34. ellapsedminutes = 0
  35. ellapsedseconds = 0
  36. ProgressBar1.Value = 0
  37. Label1.Text = ellapsedminutes & " min " & ellapsedseconds & " sec"
  38. Timer1.Enabled = True
  39. End Sub
  40.  
  41. End Class
  42.  
  43.  
Oct 13 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.