点击窗体上的“X”关闭使之最小化到托盘,然后右击弹出菜单,选择“关闭”如何完全关闭?private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{ this.WindowState = FormWindowState.Minimized;
e.Cancel = true;
} private void Form1_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState ==FormWindowState.Minimized )
{
this.Hide();
this.notifyIcon1.Visible = true;
}
}
========
这是我单击"X"按钮时,代码
请教高手,如何退出程序
{ this.WindowState = FormWindowState.Minimized;
e.Cancel = true;
} private void Form1_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState ==FormWindowState.Minimized )
{
this.Hide();
this.notifyIcon1.Visible = true;
}
}
========
这是我单击"X"按钮时,代码
请教高手,如何退出程序
{
if (result == DialogResult.Yes)
{
e.Cancel = false;
Application.Exit();
}
else
{
e.Cancel = true;
this.Hide();
this.Visible = false;
}
}private void ConExit_Click(object sender, EventArgs e)
{
result=MessageBox.Show("确认退出系统?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
Application.Exit();
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!this.m_allowExit)
{
this.WindowState = FormWindowState.Minimized;
e.Cancel = true;
}
}然后在弹出的菜单的Click事件里设置这个this.m_allowExit=true;
这样窗口就会顺利的关闭了.
如果不行的话设置一个变量,在formClosing中根据变量的值来设置e。Cancel的值
/// 重写窗体关闭事件
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
if (m.Msg == WM_SYSCOMMAND && (int) m.WParam == SC_CLOSE)
{
this.Hide();
return;
}
base.WndProc (ref m);
}