在C中自动关闭消息框#
答
您需要创建自己的窗口,把代码隐藏包含加载处理程序和定时器处理程序如下:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Timer t = new Timer();
t.Interval = 3000;
t.Elapsed += new ElapsedEventHandler(t_Elapsed);
t.Start();
}
void t_Elapsed(object sender, ElapsedEventArgs e)
{
this.Dispatcher.Invoke(new Action(()=>
{
this.Close();
}),null);
}
然后,您可以让您的自定义消息框出现调用的ShowDialog() :
MyWindow w = new MyWindow();
w.ShowDialog();
答
System.Windows.MessageBox.Show()方法有一个重载,它将owner窗口作为第一个参数。如果我们创建一个隐藏的所有者窗口,然后我们在指定的时间后关闭它,那么它的子消息框也会关闭。
下面是完整的答案:https://*.com/a/20098381/2190520
使用定时器..... – 2010-12-06 00:32:10