dev775
asked on
Progress Bar Bound to Timer
Using C# I need to create a simple form that contains a progress bar that moves from 0% to 100% over a fixed, linear 20 second duration. Above the progress bar I have a label control to display a message. At 8 seconds and again at 15 seconds I need to change the text in the label. When the timer times out I then want to display a button which will allow the user to close the form. Assistance to write some simple code to achieve this function is much appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Lol...c'mon now! I even started my post off with "There are so many ways to go about this..."
I love seeing multiple different approaches in a thread! =)
I love seeing multiple different approaches in a thread! =)
ASKER
Idle Mind - thank you for such a complete response. After copying your code and compiling I received an error for the "using System.Linq". I am using VS2005. I removed this line and then there were no complie errors but the program did not work. I'm stuck - please help!
No problem...where are you at? Which part doesn't work?
Did you you wire up the button handlers to the correct methods in the code?
(Select the control, use the "lightning bolt" icon to find the event, then use the dropdown to pick the right method)
Does Form2 open when Button1 is pressed in Form1?
If Form2 opens, does the ProgressBar move?
etc...
Did you you wire up the button handlers to the correct methods in the code?
(Select the control, use the "lightning bolt" icon to find the event, then use the dropdown to pick the right method)
Does Form2 open when Button1 is pressed in Form1?
If Form2 opens, does the ProgressBar move?
etc...
ASKER
Idle Mind... you are exactly correct, the solution was to "wire up" the handlers (as you put it!). I didn't realize this was necessary - apparently when you drag-and-drop the controls using the VS designer this step isn't required. I am learning very much - thanks. Last question... suppose I want to eliminate form2 and have the little program just run upon lauching, then close when button1 is clicked? Does this require many changes? Thank you again for the great help!
ASKER
anarki_jimbel: your solution worked as well. I am examing the code from your solution and from Idle Mind and trying to learn some things. Thanks very much!
To change the "startup form" you double click on "program.cs" in the Solution Explorer in the top right of the IDE. Then change the form that is passed into the Application.Run() call to that of the form you want to start the app with.
To make the app exit when the button is clicked you would just change it to:
this.Close();
To make the app exit when the button is clicked you would just change it to:
this.Close();
ASKER
This was a very thorough response from both experts - one of the best I have received from many questions that I have posted to EE.
Here is how I displayed the dialog:
public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.ShowDialog(this);
}
}
Here is the dialog:
Open in new window