Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.


Back to Forum: Tech Off
  • User profile image

    In Vb can anyone help with how to create a form that has a clock in it. So I can use it to tell the time.

    Do I need to create a thread when the form loads ?

    Or is there a clock obect with a tick event that I can use ?
    Is this the right approach ?

  • User profile image

    Drag a label and a Timer onto your form, and double click the form itself. Make sure you start the timer in the Constructor of the form, as seen in line 6. Then, in the Tick event of the timer, update the label.Text property to the current time, as seen in line 11.

    Hope that helps.
      .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: Consolas, "Courier New", Courier, Monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

       1:      public partial class Form1 : Form
       2:      {
       3:          public Form1()
       4:          {
       5:              InitializeComponent();
       6:              timer1.Start();
       7:          }
       9:          private void timer1_Tick(object sender, EventArgs e)
      10:          {
      11:              label1.Text = DateTime.Now.ToString();
      12:          }
      13:      }

  • User profile image

    Brilliant, thanks.

  • User profile image

    It worked

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.