GUI and timer : Time « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » TimeScreenshots 
GUI and timer
GUI and timer

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Clock
{
  /// <summary>
  /// Summary description for ClockForm.
  /// </summary>
  public class ClockForm : System.Windows.Forms.Form
  {
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Timer timer1;
    private System.Windows.Forms.Label label2;
    private System.ComponentModel.IContainer components;

    #region ClockForm Constructor
    public ClockForm()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
      // The following line sets the text for the label box.
      // To display no text, simply use two quote marks.
      label1.Text = "";
      // The following two statements set the text size and
      // cause the time to appear centered in the label box
      label1.Font = new System.Drawing.Font
        ("Microsoft Sans Serif"24);
      label1.TextAlign = ContentAlignment.MiddleCenter;
      label2.Font = label1.Font;
      label2.TextAlign = ContentAlignment.MiddleCenter;
      // This.Text is the text that will appear in the form's
      // title bar.
//      this.Text = "My Clock";
      // The following three lines set the timer to tick
      // every second (1000 milliseconds), start the timer and
      // write the initial time to the label box
      timer1.Interval = 1000;
      timer1.Start ();
      SetClock ();
    }
    #endregion
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Disposebool disposing )
    {
      ifdisposing )
      {
        if (components != null
        {
          components.Dispose();
        }
      }
      base.Disposedisposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.components = new System.ComponentModel.Container();
      this.timer1 = new System.Windows.Forms.Timer(this.components);
      this.label1 = new System.Windows.Forms.Label();
      this.label2 = new System.Windows.Forms.Label();
      this.SuspendLayout();
      // 
      // timer1
      // 
      this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
      // 
      // label1
      // 
      this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif"24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      this.label1.Location = new System.Drawing.Point(2456);
      this.label1.Name = "label1";
      this.label1.Size = new System.Drawing.Size(24848);
      this.label1.TabIndex = 0;
      this.label1.Text = "label1";
      // 
      // label2
      // 
      this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif"24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      this.label2.Location = new System.Drawing.Point(24136);
      this.label2.Name = "label2";
      this.label2.Size = new System.Drawing.Size(24848);
      this.label2.TabIndex = 1;
      this.label2.Text = "label2";
      // 
      // ClockForm
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(615);
      this.ClientSize = new System.Drawing.Size(292272);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.label2,
                                      this.label1});
      this.Name = "ClockForm";
      this.Text = "ClockForm";
      this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new ClockForm());
    }

    private void timer1_Tick(object sender, System.EventArgs e)
    {
      SetClock ();
    }
    protected void SetClock ()
    {
      string str = DateTime.Now.ToString();
      int index = str.IndexOf (" ");
      label1.Text = str.Substring (index + 1);
      label2.Text = str.Substring (0, index);
    }
  }
}


           
       
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.