Solved

Simple Form Question

Posted on 2006-06-29
1
220 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 250 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now