Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can follow these steps to display the present date and time in the text property of your C# Windows Form application:

  1. Drag and drop a Label control onto your form from the Toolbox.
  2. Select the Label control, and in the Properties window, locate the Text property.
  3. Click the "..." button next to the Text property to open the String Collection Editor.
  4. Type the following code in the editor:

    DateTime dt = DateTime.Now; label1.Text = "Current Date and Time: " + dt.ToString();

  5. Click OK to close the editor and save the changes.

  6. Run your application, and you should see the present date and time display on the Label control.