Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Simple Form Question

Posted on 2006-06-29
1
Medium Priority
?
267 Views
Last Modified: 2010-04-17
I have a C# form with three objects.
A label, a textfield and a button.
When the button is pressed, it will run a for loop
run where i=0 until i=integer entered in text field.

I want to do it where if the number entered is large then after the button is pressed, the label will say "Running..." until it's done, then "completed." when it's done.

here's my code

            label2.Text = "Running.";
            for (int i = 0; i < Convert.ToInt32(textBox1.Text); i++)
            {
            }
            label2.Text = "Completed.";

I know it's amateurish to do it this way cuz it doesn't work. It will freeze until it's done counting then label2.Text will just = "Completed."  And "running." is never seen.

How do I code it so it will say "Running" after the button is pressed and show "Completed" when it is completed?
0
Comment
Question by:flam79
1 Comment
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 1000 total points
ID: 17014275
One approach would be to call Application.DoEvents() in your loop, this will process any windows messages that are waiting, try:

            label2.Text = "Running.";
            for (int i = 0; i < Convert.ToInt32(textBox1.Text); i++)
            {
                    //... some processing here
                    Application.DoEvents();
            }
            label2.Text = "Completed.";
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Six Sigma Control Plans
Screencast - Getting to Know the Pipeline

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question