How can I show a message in the statusBar for 5 seconds?
I do some code, on the end I write out a message in statusBar (statusBar.Text = "Notification Message"; ).
But I want that is shown for only 5 seconds. Then it dissapears (with statusBar.Text = ""; )

How can I do this?

Got to. It works:

public class Form1 : Form {//Do something like following in your form
    System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
    StatusBar statusBar1 = new StatusBar();

    // This is the method to run when the timer is raised.
    private void TimerEventProcessor(Object myObject,
                                            EventArgs myEventArgs) {
       myTimer.Stop();
       statusBar1.Text="";
       myTimer.Tick -= TimerEventProcessor;
     }

    public void SetStatusBar() {
       /* Adds the event and the event handler for the method that will 
          process the timer event to the timer. */
       myTimer.Tick += new EventHandler(TimerEventProcessor);

       // Sets the timer interval to 5 seconds.
       myTimer.Interval = 5000;

       statusBar1.Text="Notification Message";
       myTimer.Start();
    }
 }

You may find this code a little easier to work with:

private void button1_Click(object sender, EventArgs e)
    {
      new Action<Control, string, int>(SetText).BeginInvoke(label1, "Notification Message", 5, null, null);
    }

    private void SetText(Control ctrl, string txt, int seconds)
    {
      this.Invoke(new MethodInvoker(
        delegate()
        {
          ctrl.Text = txt;
        }));
      System.Threading.Thread.Sleep(seconds * 1000);
      this.Invoke(new MethodInvoker(
        delegate()
        {
          ctrl.Text = string.Empty;
        }));
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.