比如说什么什么条件下,messagebox.show了
如果人工不去点确认,如何做到自己定时10s或者5s自动点确认呢?
private void button1_Click(object sender, EventArgs e)
{
Form msg = new Form();
Task.Run(new Action(() =>
{
Thread.Sleep(4000);
Invoke(new Action(() =>
{
msg.Close();
}));
}));
MessageBox.Show(msg, "TEST");
}
定时器 Timer 设置几秒。 弹框时 启用定时器,定时器结束之后 关闭弹窗
NuGet程序包:AutoClosingMessageBox也许可以帮助你。
示例如下:
// 默认一秒后关闭
AutoClosingMessageBox.Show("Hello, World!");
或者自定义参数,如下:
var result = AutoClosingMessageBox.Show(
text: "提示内容?",
caption: "操作提示",
timeout: 2500,
buttons: MessageBoxButtons.YesNo,
defaultResult: DialogResult.Yes);
if(result == DialogResult.Yes) {
// 确认
}
else {
// 取消
}