AllTheTimeWorld.com

csharp richtextDisplay the date and time on timer tick.

Display the date and time on timer tick.

Timer event: toolStripStatusDateTime.Text = System.DateTime.Now.ToString();

Display the date and time on timer tick.

Timer event: toolStripStatusDateTime.Text = System.DateTime.Now.ToString();

We will display the date and time in the status bar.

Enable the timer either in the properties window, or by adding the code to form load.

Write the code as shown below:

private void Form1_Load(object sender, EventArgs e)
{
   // At timer1 tick display date and time
   timer1.Enabled = true;
   // Position the rich text box to left, under the toolstrip.
   richTextBox1.Top = toolStrip1.Top + toolStrip1.Height;
   richTextBox1.Left = 0;
   resizeRichText();
}

private void timer1_Tick(object sender, EventArgs e)
{
   // Display date and time.
   toolStripStatusDateTime.Text = System.DateTime.Now.ToString();
}
  • Click Save All at this point and run the program to see what you have so far.