473,503 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cant get label to update label.text

Hello, Am new to C# and am playing around trying to get a while loop to
display a int on a windows console using label.

private void btnGo_Click(object sender, System.EventArgs e)
{
int Counter = 0;
while ( Counter < 10 )
{
lblMain.Text =Counter.ToString();
System.Threading.Thread.Sleep(5000);
Counter++;
} //WHile

This is the button the starts the loop which is supposed to show the
value of Counter on the label (lblMain) text field....if I run the loop
it runs fine but doesnt change the value of the text field until right
at the end...when it displays a 9. I have included the Sleep command
incase it was running too fast for me to see, but that isnt the
case....

Any clever comments anyone?

Thanks

Nov 17 '05 #1
3 21057
Sorry - probably didnt make the question clear - why cant I see the
variable Counter counting up from 1 to 9?

Nov 17 '05 #2
Hello kaiser,

Just add one line:
int Counter = 0;
while ( Counter < 10 )
{
label1.Text =Counter.ToString();
Application.DoEvents(); //Refresh(); and Update(); also work. You have
to choose the right one for you.
System.Threading.Thread.Sleep(2000);
Counter++;
}

-----
Ariel Popovsky
Hello, Am new to C# and am playing around trying to get a while loop
to display a int on a windows console using label.

private void btnGo_Click(object sender, System.EventArgs e)
{
int Counter = 0;
while ( Counter < 10 )
{
lblMain.Text =Counter.ToString();
System.Threading.Thread.Sleep(5000);
Counter++;
} //WHile
This is the button the starts the loop which is supposed to show the
value of Counter on the label (lblMain) text field....if I run the
loop it runs fine but doesnt change the value of the text field until
right at the end...when it displays a 9. I have included the Sleep
command incase it was running too fast for me to see, but that isnt
the case....

Any clever comments anyone?

Thanks

Nov 17 '05 #3
Great...thanks

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2294
by: Burghew | last post by:
Hi all, I have 3 unbound combo boxes in my form which basically helps me to filter for values. I need to update a text box which will be stored with the value I receive after filtering with the...
1
3421
by: John Davis | last post by:
I am writing a program that allows user to select the date in a calendar, and it will update the text fields automatically. I created 2 forms. The first form has 2 text fields (start date and...
5
2988
by: David-L. Nadeau | last post by:
Hi ! I have a little problem. I have a process that runs when a user click a button. The process is long to execute (+/- 5 minutes). So, I put a progress bar and now I want to show the evolution...
4
4929
by: Ron | last post by:
Hello, I created an array of label controls like this: Dim lbl() As Label = {Me.lbl1, Me.lbl2, Me.lbl3} and was able to iterate through the array. But then I saw another way to declare the...
7
2926
by: Hexman | last post by:
In my program I have several labels that I want to update with information that is being processed in a calculation module. I have code similar to the following in my module. As it goes through...
4
5010
by: Ryan | last post by:
I've got a little bit of code that runs when you enter data in a datasheet view (which is a subform of the form you are in) if rst!DateReceived >= 30 Then Forms!DisposalRecords.Label90.Caption =...
1
2109
by: Durango2008 | last post by:
I have a C# .NET webapp that I am working on. I setup a textbox that gets validation performed on it, and if there is an error upon validation on the input I set a label to inform the user what...
1
1531
by: yoavkarmon | last post by:
private void domainUpDown1_SelectedItemChanged(object sender, EventArgs e) { Label labeli = new Label; for (int i = 0; i < 2; i++) { ...
0
1208
by: Marshall | last post by:
Hi In this code everything works fine without any errors, when i edit the row it goes well, but when i change the text in the textbox and press update it still shows the same in gridview row. it...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.