[英]How would I make a messageBox not show within a time limit of a button click? c#
我正在程序中創建一個保存系統,我想將其保存在如果您未在1分鍾內保存日志的地方,它將出現一個消息框。 換句話說,如果您在1分鍾內單擊一個按鈕,我希望messageBox不顯示。 我將如何去做呢?
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
DialogResult choice = MessageBox.Show(" Would you like to save the Log?", "Save Log?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk);
if (choice == DialogResult.Yes)
{
button6.PerformClick();
e.Cancel = false;
}
else if (choice == DialogResult.No)
{
e.Cancel = false;
}
}
}
您可以檢查日志保存窗口是否仍然打開。 接下來,您可以使用Thread.sleep(miliseconds)創建一個線程,並在延遲超過消息框后顯示。 您可以在窗口退出時創建一個函數,以便在日志窗口在一分鍾內關閉時也將激活消息框。
private void CreateTimer()
{
static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
myTimer.Tick += new EventHandler(TimerEventProcessor);
// Sets the timer interval to 1 minute.
myTimer.Interval = 60000;
myTimer.Start();
}
private static void TimerEventProcessor(Object myObject,
EventArgs myEventArgs) {
myTimer.Stop();
// Write code here to show the message box asking the user to save
// Once the user has saved restart the timer
myTimer.Start();
}
請記住,當用戶保存時,您需要停止並啟動計時器。 在您的保存方法中編寫該代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.