📄 timercontrol.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace MineClearance
{
/// <summary>
/// Summary description for TimerControl1.
/// </summary>
public class TimerControl : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Label label1;
public EventHandler Rouse;
private int RouseTime;
public int rouseTime
{
get
{
return RouseTime;
}
set
{
RouseTime = value;
}
}
private int SpendTime;
public int spendTime
{
get
{
return SpendTime;
}
set
{
if(0 <= SpendTime && SpendTime != value)
{
SpendTime = value;
ReDraw();
if(SpendTime == rouseTime && Rouse != null)
{
Rouse(this, EventArgs.Empty);
}
}
}
}
public TimerControl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
this.Size = new Size(48, 24);
Clear();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component 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.SuspendLayout();
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// label1
//
this.label1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.label1.BackColor = System.Drawing.Color.Gainsboro;
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.ForeColor = System.Drawing.Color.Red;
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 24);
this.label1.TabIndex = 0;
this.label1.Text = "000";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// TimerControl
//
this.BackColor = System.Drawing.Color.Gainsboro;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label1});
this.Name = "TimerControl";
this.Size = new System.Drawing.Size(48, 24);
this.ResumeLayout(false);
}
#endregion
public void ReDraw()
{
label1.Text = spendTime.ToString();
while(label1.Text.Length < 3)
{
label1.Text = "0" + label1.Text;
}
}
public void Start()
{
timer1.Start();
}
public void Stop()
{
timer1.Stop();
}
public void Clear()
{
this.Stop();
spendTime = 0;
}
private void timer1_Tick(object sender, System.EventArgs e)
{
spendTime ++;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -