【发布时间】:2014-07-04 17:17:36
【问题描述】:
我有这个程序,其中我使用计时器重定向到另一个页面。它确实有效,但问题是当我单击取消按钮时,会出现一个消息框,当用户不点击它并且计时器滴答作响时,消息框没有关闭。如何自动关闭消息框??
这就是它的样子..
这是我用来重定向页面的代码
DispatcherTimer sessionTimer = new DispatcherTimer();
public CashDepositAccount()
{
InitializeComponent();
con = new SqlConnection(ConfigurationManager.ConnectionStrings["kiosk_dbConnectionString1"].ConnectionString);
con.Open();
SqlCommand cmd1 = new SqlCommand("Select idle From [dbo].[Idle]", con);
idle = Convert.ToInt32(cmd1.ExecuteScalar());
InputManager.Current.PreProcessInput += Activity;
activityTimer = new DispatcherTimer
{
Interval = TimeSpan.FromMinutes(idle),
IsEnabled = true
};
activityTimer.Tick += Inactivity;
}
#region
void Inactivity(object sender, EventArgs e)
{
navigate = "Home";
Application.Current.Properties["navigate"] = navigate;
}
void Activity(object sender, PreProcessInputEventArgs e)
{
activityTimer.Stop();
activityTimer.Start();
}
当我在计时器计时时重定向到主页时如何关闭消息框?
【问题讨论】:
-
我假设您使用的是标准
MessageBox.Show()。您可能希望滚动自己的小对话框窗口,并在其上使用公共方法以在计时器到期时将其关闭。 -
我不能只使用标准的 MessageBox.Show() 吗??
-
您可以 - 通过一些 WinAPI 调用(发送
WM_CLOSE到消息框实例)。见这里:stackoverflow.com/a/19636437/1517578 -
好吧,我不知道 :)
-
谢谢。我试试这个
标签: c# timer messagebox auto-close