C#在Windows窗体中,按钮不能单击两分钟,显示一条消息

问题描述:

如果在Windows窗体应用程序中某个特定按钮没有在两分钟内单击,我想显示一条消息以单击该按钮.请提出建议.

If In a windows form application a specific button not click around two minutes, I want to display a message to click he button. Please advise.

在表单上放置所需时间的计时器,然后在其打勾时向用户抛出一个消息框.
Place a timer on your form with the duration you want and then throw up a message box to the user when it ticks.


1.在类中创建一个bool值以检查按钮的状态(单击或未单击)
1.create a bool value in the class to check status of button(clicked or not clicked)
bool IsClicked = false;



2.如果单击按钮,则将IsClicked设置为true.因此在button.click中添加以下行.单击处理方法



2.set IsClicked to true if button is clicked.so add below line within button.click handling method

bool IsClicked = true;


3.添加以下内容以形成加载事件处理方法.
如果尚未设置IsClicked,它将启动计时器并显示一个消息框.


3.add following to form load event handling method.
It starts the timer and shows a messagebox if IsClicked is still not set.

Timer timer = new Timer();
timer.Start();
timer.Interval = 120000;
timer.Tick += new EventHandler((o, b) => {if(!IsClicked)MessageBox.Show("Please click the button");});