ç±äºç®åç¨å°äºC#çæå ³ç¥è¯ï¼ä½ä¹å没æC#çåºç¡ï¼æ以è¶çæºä¼æ£å¥½å¦ä¹ å¦ä¹ ã
æ¬ç¯åæï¼è®°å½ä¸å©ç¨C#å®ç°ä¸ä¸ªç®åçç§è¡¨è®¡æ¶å¨ï¼åºæ¬çé¢å¦ä¸å¾ã
åè½è¯´æï¼ç¹å»âå¼å§âå¼å§è®¡æ¶ï¼ç¹å»âæåâæå计æ¶ï¼ç¹å»ââåæ¢ââåæ¢è®¡æ¶ï¼åç¹å»âå¼å§âï¼éæ°å¼å§è®¡æ¶ã
é¦å ï¼æ们å¨çªä½è®¾è®¡çªå£ç»åºè¯¥çé¢ï¼ç±1个Labelï¼3个buttonææãåå»æé®æ·»å äºä»¶ã
æ ¸å¿é¨åæ¯ç¨ç§è¡¨å¯¹è±¡Stopwatchåæ¶éTimerå®ç°çã
ç¨åºæºä»£ç å¦ä¸ï¼
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace Ch04Ex04
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Timer time = new Timer();
Stopwatch sw; //ç§è¡¨å¯¹è±¡
TimeSpan ts;
static int count = 1;
private void button1_Click(object sender, EventArgs e)
{
//å¼å§æé®
button2.Enabled = true;
button3.Enabled = true;
if(button2.Text == "继ç»") //å¼å§åå°ç»§ç»æé®é置为æå
button2.Text = "æå";
sw = new Stopwatch();
time.Tick += new EventHandler(time_Tick); //æ¶é触åä¿¡å·
time.Interval = 1;
sw.Start();
time.Start();
}
void time_Tick(object sender, EventArgs e)
{
ts = sw.Elapsed;
label1.Text = string.Format("{0}:{1}:{2}:{3}", ts.Hours, ts.Minutes, ts.Seconds,ts.Milliseconds/10);
}
private void button3_Click(object sender, EventArgs e)
{
//åæ¢æ¶é´æé®
sw.Stop();
time.Stop();
label1.Text = string.Format("{0}:{1}:{2}:{3}", 0, 0, 0, 0);
}
private void Form1_Load(object sender, EventArgs e)
{
button2.Enabled = false;
button3.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
if (button2.Text == "æå")
{
//æåäºä»¶æé®
button2.Text = "继ç»";
sw.Stop();
time.Stop();
}
else if (button2.Text == "继ç»")
{
//继ç»äºä»¶
button2.Text = "æå";
sw.Start();
time.Start();
}
}
}
}
ç§è¡¨è¿è¡ç»æå¦å¾æ示ã
ä¸ä¸æ¥å·¥ä½ï¼å¨å·¦ä¸æ¹æ·»å ä¸ä¸ªlabelï¼å®éªå¤æ¬¡æåçåè½ï¼å³è½ä¿åç§è¡¨çå¤ä¸ªä¸é´ç»æï¼å¦è®°å½å¤ååå¦çé¿è·æ绩çæ¶åï¼æåæé®åªæ¯è®°å½å°è¾¾ç»ç¹çåå¦çæ绩ï¼è®¡æ¶è¿å¨ç»§ç»ï¼è¿ä¸ªåè½ä¸é¾å®ç°ï¼ç»èªå·±ä¹ç»åä½ä¸ä¸ªå¨æçä½å°ã
-------------------------------------------------------------------------------------------------------
以ä¸æ¯çªä½è®¾è®¡å¨èªå¨çæç代ç ï¼è¾ å©åèã
#region Windows çªä½è®¾è®¡å¨çæç代ç
/// <summary>
/// 设计å¨æ¯ææéçæ¹æ³ - ä¸è¦
/// 使ç¨ä»£ç ç¼è¾å¨ä¿®æ¹æ¤æ¹æ³çå
容ã
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(204, 78);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(38, 23);
this.button1.TabIndex = 0;
this.button1.Text = "å¼å§";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(205, 163);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(37, 23);
this.button3.TabIndex = 2;
this.button3.Text = "åæ¢";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// label1
//
this.label1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.label1.Font = new System.Drawing.Font("å®ä½", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(30, 33);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(202, 42);
this.label1.TabIndex = 3;
this.label1.Text = "0:0:0:0";
//
// button2
//
this.button2.Location = new System.Drawing.Point(205, 122);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(38, 23);
this.button2.TabIndex = 4;
this.button2.Text = "æå";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.button2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button3);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.RightToLeftLayout = true;
this.Text = "ç§è¡¨";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
如何用c#做一个秒表
首先,我们在窗体设计窗口画出该界面,由1个Label,3个button构成。双击按钮添加事件。核心部分是用秒表对象Stopwatch和时钟Timer实现的。程序源代码如下:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text...
利用c#软件,在Windows窗口下编写一个秒表程序,具体要求如下
利用c#软件,在Windows窗口下编写一个秒表程序,具体要求如下 编写Windows窗体应用程序,利用Timer控件,设计秒表。说明:Timer控件的添加定义全局变量ticks,在Form_Load事件中初始化为0。Timer控件的Tick事件代码参考如下:ticks++;longhours=t... 编写Windows窗体应用程序,利用Timer控件,设计秒表。说明:Timer控件的添加定义全...
C#计时器 比如秒表怎么设计?
label1.Text = String.Format("{0}天{1}小时{2}分{3}秒{4}毫秒", ts.Days, ts.Hours, ts.Minutes, ts.Seconds,ts.Milliseconds );} private void timer1_Tick(object sender, EventArgs e){ TimeSpan ts = sw.Elapsed;label1.Text = String.Format("{0}天{1}小时{2}分{3}秒{4}...
用c#设计秒表代码程序
timer1.Enabled = false;label1.Text = (DateTime.Now - TimeStart).ToString();} private void timer1_Tick(object sender, EventArgs e){ label1.Text = (DateTime.Now - TimeStart).ToString();}
请问如何用C#编一个简单的秒表程序?
private void form1_Load(object sender, EventArgs e){ Timer timer = new Timer();timer.Interval = 1000;timer.Tick += new EventHandler(timer_Tick);timer.Enabled = true;label1.Text = DateTime.Now.ToShortTimeString();} void timer_Tick(object sender, EventArgs e){ label1.Text = (...
c#中时间控件 如何在winform程序exe开始运行的时候,就要计时
在C#中有一个秒表类:stopwatch,用这个类可以方便的测试一下代码运行时间。要使用stopwatch要先加一个命名空间,System.Diagnostics。具体用法如下:Stopwatch timer = new Stopwatch();\/\/new一个stopwatch long total = 0;timer.Start();\/\/开始计算时间 for (long i = 1; i <= 100000000; i+...
c#windows窗体应用程序简易秒表
这样当然不行,windows中的定时器也就是你用的timer,精度最高只有15—55毫秒左右(并不是恒定的),即使你设成1也是没用的,而且你考虑一点,即使用最小的55毫秒,从计算到显示完成,用的时间也不止55毫秒了
如何用C语言编程,使出现一个界面几秒后自动跳到另一个界面;求高手解答...
给个代码你参考下吧,是秒表计时器程序的代码 include <stdio.h> include <conio.h> include <windows.h> include <stdlib.h> struct tm \/\/定义时间结构体,包括时分秒和10毫秒 { int hours,minutes,seconds;int hscd;}time,tmp,total; \/\/time用以计时显示,tmp用以存储上一阶段时间,to...
c# WPF,用定时器方法,,一个开始按钮,一个停止按钮,点开始开始计时_百度...
首先新建一个Timer实例,Timer有 System.Timers.Timer;System.Threading.Timer;等多种,用法不一,但大致是一样的。在初始化函数里面,对Timer进行初始化,设定100毫秒定时,并设定超时事件触发函数,在触发函数中,通过Invoke委托更新前台秒表显示,开始按钮和停止按钮,设定点击事件函数,开始事件函数中,对...
能用C语言写程序吗?例如WPF或能在win7上运行的软件?
打开VS2010,新建一个工程,语言选择C# ,再选择WPF Application项目,确定之后就生成了一个最简单的WPF应用软件,点击运行(或者F5),这个软件就运行了,当然,你什么代码都没写,框架只帮你生成一个最简单的框架,然后你就可以把QQ上的按钮啊,功能啊往上面添加了 想要快点做出软件,我建议你直接用C...