Share via


hide a label after a few second as status bar

Question

Monday, February 27, 2017 9:11 PM

hello comrade 

i need that when my form is loaded a label after a few second hide (visible = false)

All replies (4)

Tuesday, February 28, 2017 4:36 PM âś…Answered

For your question, you could use Thread.Sleep() to get what you want.

   private void button1_Click(object sender, EventArgs e)
        {
            Thread.Sleep(3000);
            label1.Visible = false;
        }

.

@Wendy, it's not a good idea to use a 3 second Thread.Sleep in a button click ... that would make the Form unresponsive for those 3 seconds!!

~~Bonnie DeWitt [C# MVP]

http://geek-goddess-bonnie.blogspot.com


Monday, February 27, 2017 11:10 PM | 1 vote

Use a timer.

      System.Windows.Forms.Timer timerHideLabel = new System.Windows.Forms.Timer();

      private void Form1_Load(object sender, EventArgs e)
      {
         timerHideLabel.Interval = 5000; // Five seconds.
         timerHideLabel.Tick += TimerHideLabel_Tick;
         timerHideLabel.Start();
      }

      private void TimerHideLabel_Tick(object sender, EventArgs e)
      {
         labelToHide.Visible = false;
         timerHideLabel.Stop();
      }

Tuesday, February 28, 2017 6:20 AM | 1 vote

Hi arman_gorjipoor,

Thank you for posting here.

For your question, you could use Thread.Sleep() to get what you want.

   private void button1_Click(object sender, EventArgs e)
        {
            Thread.Sleep(3000);
            label1.Visible = false;
        }

Here is the output.

I hope this would be helpful.

Best Regards,

Wendy

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].


Tuesday, February 28, 2017 12:50 PM

how can i call you comrade ?

tnx very much