public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
//定义时分
int h = 0;
int m = 0;
int s = 0;
//保存事件
private void button1_Click(object sender, EventArgs e)
{
h = dateTimePicker1.Value.Hour;//时
m = dateTimePicker1.Value.Minute;//分
s = dateTimePicker1.Value.Second;//秒
timer1.Enabled = true;
timer1.Start();
}
//定时扫描
private void timer1_Tick(object sender, EventArgs e)
{
if (DateTime.Now.Hour == h && DateTime.Now.Minute == m && DateTime.Now.Second == s)
{
MessageBox.Show("当前时间:" + DateTime.Now + " 时间已到!");
timer1.Stop();
timer1.Enabled = false;
return;
}
}
}