Windows Develop Bookmark and Share   
 index > Windows Forms General > How do I show counted numbers in Label or Status Strip?
 

How do I show counted numbers in Label or Status Strip?

I just wanted to show a countdown in a label or in the status strip label after someone pushes a button.

I put a simple for code to iterate 5000 times and show in the label and also tried the status strip label . But all it ever shows is the final number ("4999").

Why doesnt this work?

for (int i = 0; i < 5000; i++)

{

this.sslabel.Text = i.ToString();

//this.tb.Text = i.ToString();

//System.Threading.Thread.Sleep(500);

}

???
tvance929  Tuesday, May 01, 2007 9:35 PM

Hi,

try refreshing your textbox, like:

Code Snippet

for (int i = 0; i < 5000; i++)

{

this.sslabel.Text = i.ToString();
this.sslabel.Refresh();

}

You may also want to use the BackgroundWorker component to make your UI more responsive...

Andrej

Andrej Tozon  Wednesday, May 02, 2007 1:15 AM

for (int i = 0; i < 5000Wink

{

this.tb.Text = (++i).ToString();

//System.Threading.Thread.Sleep(500);

}

Karthik Krishnaswami  Tuesday, May 01, 2007 11:03 PM

Thank you! But I still get the same result. I only see the final number. I was hoping to watch the numbers climb.....

Thanks anyway.

tvance929  Tuesday, May 01, 2007 11:13 PM

Hi,

try refreshing your textbox, like:

Code Snippet

for (int i = 0; i < 5000; i++)

{

this.sslabel.Text = i.ToString();
this.sslabel.Refresh();

}

You may also want to use the BackgroundWorker component to make your UI more responsive...

Andrej

Andrej Tozon  Wednesday, May 02, 2007 1:15 AM

Hi

You can use a timer to achieve this. The following lines of code are just for your information.

Code Snippet

Databinding

public partial class Form6 : Form

{

public Form6()

{

InitializeComponent();

}

int i = 0;

private void timer1_Tick(object sender, EventArgs e)

{

this.label1.Text = i.ToString();

if (i < 5000)

i++;

else

this.timer1.Enabled = false;

}

private void button1_Click(object sender, EventArgs e)

{

this.timer1.Enabled = true;

i = 0;

}

}

You can use google to search for other answers

Custom Search

More Threads

• NotificationIcon right click to show panel
• KeyDown Event, IsInputKey not working (C#)
• About Threading
• Copy all data from Datagridview into a new datatable
• Windows Media Player 9
• Resize a Rotated Shape
• Sharing same db connection between base and derived constructors
• Alternating between two images every 3 seconds using a timer
• MSHTML Hosting
• Mdi child does not show On SpliterContainerPanel