我有這個程序,其中我使用計時器重定向到另一個頁面。它可以工作,但問題是當我點擊取消按鈕時會出現一個消息框,當用戶不會點擊它並且計時器打勾時,messagebox沒有關閉。我怎樣才能自動關閉消息框?自動關閉消息框
這是什麼樣子..
,這裏是我用來重定向頁面
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到消息箱實例)。看到這裏:http://stackoverflow.com/a/19636437/1517578 –