|
-
Dec 14th, 2009, 10:20 AM
#1
Thread Starter
Junior Member
ProgressBar question
Hello, I'm new to VB and I'm making my first Application.
I want my ProgressBar to start loading when MessageBoxButton.OK is pressed.
This is my code:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("My Text", "My Title", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, False)
If AcceptButton Then
ProgressBar1.Start()
End If
End Sub
This is the part I'm having problems with.
Code:
If AcceptButton Then
ProgressBar1.Start()
Also, I'd like the ProgressBar1 to finish after a certain time after it started. How do I do that?
-
Dec 14th, 2009, 11:14 AM
#2
Fanatic Member
Re: ProgressBar question
you move the progressbar by using ProgressBar1.Value, this has to be between the min and max levels.
If the progressbar is timer based setup a timer or a stopwatch on the form and use that to set the value (having setup already the max and min values)
If debugging is the process of removing bugs, then programming must be the process of putting them in.
-
Dec 14th, 2009, 02:01 PM
#3
Thread Starter
Junior Member
Re: ProgressBar question
For example, I want my progress bar to start when OK Button from a MsgTextbox and load up to 100% in 5 minutes, which would be the code?
-
Dec 14th, 2009, 02:17 PM
#4
Fanatic Member
Re: ProgressBar question
post removed as explained reason why in following post...
Last edited by Megalith; Dec 14th, 2009 at 02:38 PM.
If debugging is the process of removing bugs, then programming must be the process of putting them in.
-
Dec 14th, 2009, 02:19 PM
#5
Re: ProgressBar question
 Originally Posted by hotlip1
For example, I want my progress bar to start when OK Button from a MsgTextbox and load up to 100% in 5 minutes, which would be the code?
We'll explain the steps you need to take and allow you to figure it out on your own. This method will allow you to learn better.
If you don't understand, then post the code you've tried and we'll help figure it out.
First, forget about the MessageBox. Figure out how the ProgressBar works and then move on to implementing it with the MessageBox. The MessageBox will be the easiest part.
There are few things you need to know about the ProgressBar. You'll need to use Timer with what you're wanting. You'll need to set the timer's interval to a specific time so that it ticks when you want. I imagine you'll probably want it to tick every second. So, in the properties pane, set the Timer's Interval property to 1000, which is one second. You'll need to set the Enabled property of the Timer to True as it is False by default.
Then you'll need to set the Minimum and Maximum vale of the ProgressBar. You'll also need to set the Step property, which controls how much the ProgressBar increases when you call PerformStep. You can do this in the Properties pane or in code like this:
vb Code:
ProgressBar1.Maximum = 300 ProgressBar1.Minimum = 0 ProgressBar1.Step = 1
Since you want the ProgressBar to finish after 5 minutes, I set the maximum property to 300. The timer will tick every second and after 300 seconds, we'll know that 5 minutes has elapsed.
You can set all of this code in the Form's Load event.
Now all you'll need to do is call ProgressBar1.PerformStep in the Timer's Tick Event.
After you get this working, we'll show you how to do it when the MessageBox's "OK" button has been pressed.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Dec 14th, 2009, 02:36 PM
#6
Fanatic Member
Re: ProgressBar question
oh yeah forgot about ProgressBar1.PerformStep better than ProgressBar1.value += 1
If debugging is the process of removing bugs, then programming must be the process of putting them in.
-
Dec 14th, 2009, 03:10 PM
#7
Thread Starter
Junior Member
Re: ProgressBar question
THAAANKS! I got it to work!
This is my code:
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("", " ", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, False)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.PerformStep()
End Sub
End Class
EDIT: I guessNow I have to do something like
Code:
If MessageBoxButton.OK Then
<Somethingto start the clock>
End If
Last edited by hotlip1; Dec 14th, 2009 at 03:13 PM.
-
Dec 14th, 2009, 03:17 PM
#8
Fanatic Member
Re: ProgressBar question
Correct you need Timer1.Enabled = True but you also need to ensure the progressbar1 properties mentioned by weirddemon are setup i.e. min max and step, this could be either in the form load event or you could use the button click
If debugging is the process of removing bugs, then programming must be the process of putting them in.
-
Dec 14th, 2009, 03:22 PM
#9
Thread Starter
Junior Member
Re: ProgressBar question
 Originally Posted by Megalith
Correct you need Timer1.Enabled = True but you also need to ensure the progressbar1 properties mentioned by weirddemon are setup i.e. min max and step, this could be either in the form load event or you could use the button click
Yep, already set that.
And were thoes the code to start the timer go?
Is this ok?
Code:
If MessageBoxButton.OK Then
Timer1.Enabled
End If
-
Dec 14th, 2009, 03:25 PM
#10
Re: ProgressBar question
After you enable the Timer, you need to start it.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Dec 14th, 2009, 03:28 PM
#11
Thread Starter
Junior Member
Re: ProgressBar question
 Originally Posted by weirddemon
After you enable the Timer, you need to start it.
Can I just set Enabled as true in its properties then do Timer1.Start()?
-
Dec 14th, 2009, 03:32 PM
#12
Thread Starter
Junior Member
Re: ProgressBar question
Also, I get MessageBoxButton.OK is not declared.
How should I refer to it?
-
Dec 14th, 2009, 03:34 PM
#13
Re: ProgressBar question
They are equivalent. Timer.Start and Timer.Enabled = True do the same thing.
http://msdn.microsoft.com/en-us/libr...rs(VS.71).aspx
-
Dec 14th, 2009, 03:37 PM
#14
-
Dec 14th, 2009, 03:44 PM
#15
Thread Starter
Junior Member
Re: ProgressBar question
Alright, I got it to work.
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("", " ", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, False)
If MessageBoxButtons.OKCanel Then
Timer1.Start()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.PerformStep()
End Sub
End Class
The only problem is that if I press cancel, the ProgressBar starts loading too.
I got to replace MessageBoxButtoms.OKCancel (highlighted it in my code), I know. But with what?
-
Dec 14th, 2009, 03:46 PM
#16
Re: ProgressBar question
The link I posted shows how to use the messagebox.
-
Dec 14th, 2009, 04:01 PM
#17
Thread Starter
Junior Member
Re: ProgressBar question
 Originally Posted by dbasnett
The link I posted shows how to use the messagebox.
Still, I don't know how to call the OK buttom from the msgbox.
-
Dec 14th, 2009, 04:05 PM
#18
Re: ProgressBar question
from the link i posted
Code:
Dim Result As DialogResult
'Displays the MessageBox
Result = MessageBox.Show(Message, Caption, Buttons)
' Gets the result of the MessageBox display. Maybe one for OK????????????
If Result = System.Windows.Forms.DialogResult.Yes Then
-
Dec 14th, 2009, 04:29 PM
#19
Hyperactive Member
Re: ProgressBar question
Here how I do it:
vb Code:
If MessageBox.Show("TEST", "CAPTION", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) = Windows.Forms.DialogResult.OK Then Label2.Text = "OK" Else Label2.Text = "NOT OK" End If
-
Dec 14th, 2009, 04:51 PM
#20
Thread Starter
Junior Member
Re: ProgressBar question
DONE! THANKS TO EVERYBODY WHO HELPED ME.!
My code:
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("", " ", MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
If System.Windows.Forms.DialogResult.OK Then
Timer1.Start()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.PerformStep()
End Sub
End Class
-
Dec 14th, 2009, 04:53 PM
#21
Fanatic Member
Re: ProgressBar question
nice solution
If debugging is the process of removing bugs, then programming must be the process of putting them in.
-
Dec 14th, 2009, 05:33 PM
#22
Re: ProgressBar question
This "If System.Windows.Forms.DialogResult.OK Then" tells me that you do not have Option Strict On, not to mention there is not a comparison. It will always evaluate to true, regardless of which button you click.
It should look something like this:
Code:
Dim dRslt As DialogResult
dRslt = MessageBox.Show("OK or Cancel", "Test", MessageBoxButtons.OKCancel)
If dRslt = Windows.Forms.DialogResult.OK Then
'ok
Else
'cancel
End If
Last edited by dbasnett; Dec 14th, 2009 at 05:39 PM.
-
Dec 14th, 2009, 05:56 PM
#23
Thread Starter
Junior Member
Re: ProgressBar question
bleh no, false, i didn't fix it omg.
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("", " ", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
If System.Windows.Forms.DialogResult.Yes Then
Timer1.Start()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.PerformStep()
End Sub
End Class
Doesn't matter if I press Yes or No, the ProgressBar will start, although in my code it says only if DialogResult.Yes
-
Dec 14th, 2009, 06:19 PM
#24
Re: ProgressBar question
That is what I said. As mentioned before, go here http://msdn.microsoft.com/en-us/libr...essagebox.aspx
and look for
"The following code example shows how to ask the user a yes or no question and make a decision based on the response."
-
Dec 14th, 2009, 06:30 PM
#25
Thread Starter
Junior Member
Re: ProgressBar question
Then what's wrong here?:
Code:
MessageBox.Show("", " ", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
Dim Result As DialogResult
If Result = System.Windows.Forms.DialogResult.Yes Then
Timer1.Start()
End If
-
Dec 14th, 2009, 06:33 PM
#26
Re: ProgressBar question
 Originally Posted by hotlip1
Then what's wrong here?:
Code:
MessageBox.Show("", " ", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
Dim Result As DialogResult
If Result = System.Windows.Forms.DialogResult.Yes Then
Timer1.Start()
End If
Compare that to this http://www.vbforums.com/showpost.php...9&postcount=22
-
Dec 14th, 2009, 06:39 PM
#27
Thread Starter
Junior Member
Re: ProgressBar question
Lol, sorry didn't read that post before :P
Now it worked, finally, without issues.
I've learned alot today! THANKS!
1 more thing:
I want to block a button after a desired time, and that after I reopen the application it is still blocked. How do I do that?
Last edited by hotlip1; Dec 14th, 2009 at 06:45 PM.
-
Dec 14th, 2009, 07:56 PM
#28
Fanatic Member
Re: ProgressBar question
similar but you are looking at button1.disable, you should know where to place this now, only issue is counting the ticks but you could use progressbar1.value to get the elapsed seconds
If debugging is the process of removing bugs, then programming must be the process of putting them in.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|