Free Blog CounterEnglish German Translation
Google

Thursday, July 17, 2008

Timer Project

Hi Guys

This is a project to get used to Time in C#.

Open a Windows Form in C#.


using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;
namespace TimerDemo

{

///

/// Summary description for Form1.

///

public class TimerDemo : System.Windows.Forms.Form

{

private System.Windows.Forms.Timer Clock;

private System.Windows.Forms.Label lbTime;

private System.Windows.Forms.Button btnStart;

protected string TimeInString;

protected int count;

private System.Windows.Forms.TextBox txtcheck;

private System.ComponentModel.IContainer components;
public TimerDemo()

{

// // Required for Windows Form Designer support

//

InitializeComponent();
// // TODO: Add any constructor code after InitializeComponent

}
public string GetTime()

{

int sec=0;

count +=sec;

return count.ToString();

}
///

/// Clean up any resources being used.

///

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}
#region Windows Form Designer generated code

///

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

///

private void InitializeComponent()

{

this.components = new System.ComponentModel.Container();

System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(TimerDemo));

this.lbTime = new System.Windows.Forms.Label();

this.Clock = new System.Windows.Forms.Timer(this.components);

this.btnStart = new System.Windows.Forms.Button();

this.txtcheck = new System.Windows.Forms.TextBox();

this.SuspendLayout();

// // lbTime //

this.lbTime.Location = new System.Drawing.Point(40, 64);

this.lbTime.Name = "lbTime";

this.lbTime.TabIndex = 0;

// // Clock //

this.Clock.Tick += new System.EventHandler(this.Timer_Tick);

// // btnStart //

this.btnStart.Location = new System.Drawing.Point(40, 104);

this.btnStart.Name = "btnStart";

this.btnStart.Size = new System.Drawing.Size(64, 24);

this.btnStart.TabIndex = 1;

this.btnStart.Text = "Start";

this.btnStart.Click += new System.EventHandler(this.btnStart_Click);

// // txtcheck //

this.txtcheck.Location = new System.Drawing.Point(48, 152);

this.txtcheck.Name = "txtcheck";

this.txtcheck.Size = new System.Drawing.Size(64, 20);

this.txtcheck.TabIndex = 2; this.txtcheck.Text = "";

// // TimerDemo //

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(292, 266);

this.Controls.Add(this.txtcheck);

this.Controls.Add(this.btnStart);

this.Controls.Add(this.lbTime);

this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

this.Name = "TimerDemo";

this.Text = "Timer Demo";

this.ResumeLayout(false);
}

#endregion
///

/// The main entry point for the application.

///

[STAThread] static void Main()

{

Application.Run(new TimerDemo());

}
private void Timer_Tick(object sender, System.EventArgs e)

{

if(sender==Clock)

{

//lbTime.Text=GetTime();

int t=Convert.ToInt32(lbTime.Text);

int s=(t+1);

lbTime.Text=s.ToString();

if(lbTime.Text == txtcheck.Text)

{

Clock.Stop();

MessageBox.Show("The Timer Has Stooped","Timer Stopped",System.Windows.Forms.MessageBoxButtons.OK);

}

}
}
private void btnStart_Click(object sender, System.EventArgs e)

{

Clock=new Timer();

Clock.Interval=1000;

Clock.Start();

Clock.Tick+=new EventHandler(Timer_Tick);
this.Controls.Add(lbTime);

lbTime.BackColor=Color.Black;

lbTime.ForeColor=Color.Red;

lbTime.Font=new Font("Times New Roman",15);

lbTime.Text=GetTime();

}

}

}




Disclaimer:Visitors who use this website and rely on any information do so at their own risk.
We are not responsible for the contents or reliability of any other websites to which we provide a link and do not necessarily endorse the views expressed within them.
While we have made efforts to ensure the accuracy of our content (consisting of
articles and information), neither this website nor the author shall be held responsible for
any losses/ incidents suffered by people accessing, using or is supplied with the content.

4 comments:

Dinesh Kudtarkar said...

The worst post I ve ever seen...

I think u must b a borin student in ur college life...

or must b a boring lecturer right now....

Fuck off

Alkesh Naik said...

Hey its not me whose boring its u who is boring u write fuckol posts may be u live at a far off village where people get happy seeing bullock carts thats why u do not know how gr8 this post is

Dinesh Kudtarkar said...

at least bullock carts r better then the fucking timer projects

Alkesh Naik said...

You look to me like a PHP developer who doesnt know nething about ASP.NET we .NET developers are far better then u PHP developers.