我想在两个文本框有相同时间发出通知或消息框时显示通知。
例如: 我有两个文本框。一个textbox1仅在短时间内显示系统时间,例如(1:05 PM),然后输入textbox1,因此第二个textbox2显示(1:06 PM),然后一分钟后,textbox1和textbox2具有相同的时间,例如(1:06 PM),然后窗口显示或仅是消息框。
//在此方法下textbox1显示当前内容并与textbox2比较 如果同时显示消息框,但不幸的是无法像:(
private void Form2_Load(object sender,EventArgs e)
{
DateTime current = DateTime.Now;
textBox1.Text = current.ToShortTimeString();
if (textBox2.Text == textBox1.Text)
{
MessageBox.Show("Okay");
}
}
//// this code to start timer in textbox1
private void timer1_Tick(object sender,EventArgs e)
{
textBox1.Text = DateTime.Now.ToShortTimeString();
timer1.Start();
}
/// this code working on add next 1 minute in textbox2
(例如:textbox1是1:05 PM,然后按Enter键textbox2显示1:06 PM)
private void textBox1_KeyDown(object sender,KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
DateTime dt = DateTime.Now;
textBox2.Text = dt.AddMinutes(1).ToShortTimeString();
}
}