Tuesday, August 24, 2010

How to control Progress Bar in Visual Basic 2008 when a user clicks Button 1 or Button 2?

I have just gotten into software development and I was wondering I have just installed Visual Basic 2008 Express Edition and started building my first Windows Form Application. Here is where I am stuck, when a user clicks button 1 I want them to see a marquee progress bar and see text or an image that says Enabled, but not stop or disappear until they click button 2 , also when a user clicks button 1 I want to run a task in the background while the user sees the marquee progress bar and image/text and the task to end when the person clicks button 2. Hopefully I am not speaking gibberish and you people understand what I am saying because like I said, I extremely new at this but slowly, very slowly, trying to understand.How to control Progress Bar in Visual Basic 2008 when a user clicks Button 1 or Button 2?
instead of progress bar use slider with min and max value when slider reaches max value reset it to min value.


How to control Progress Bar in Visual Basic 2008 when a user clicks Button 1 or Button 2?
Try this:


Add a label, a timer and 2 buttons.


Size your form to 300 by 300.


Cut and paste this into the code pane.


Play around with the ';x'; value and the timer interval.





Public Class Form1


Dim x, y As Long





Private Sub Timer1_Tick(ByVal Sender As Object, ByVal e As EventArgs) Handles Timer1.Tick





x = x - 5


Label1.Location = New Point(x, y)


If x %26lt; -20 Then x = 300








End Sub





Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


x = 350


y = 10





Button1.Text = ';Start';


Timer1.Enabled = True








End Sub





Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click





Button2.Text = ';Stop';


Timer1.Enabled = False





End Sub


End Class





: )

No comments:

Post a Comment