private void dataGrid_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if( e.KeyCode == Keys.Escape )
{ buttonExit_Click(sender, e);
}
if (e.Control && (e.KeyCode == Keys.F4))
{
buttonExit_Click( sender, e);
}
if (e.Alt && (e.KeyCode == Keys.F4))
{
Application.Exit()
}
}
{
if( e.KeyCode == Keys.Escape )
{ buttonExit_Click(sender, e);
}
if (e.Control && (e.KeyCode == Keys.F4))
{
buttonExit_Click( sender, e);
}
if (e.Alt && (e.KeyCode == Keys.F4))
{
Application.Exit()
}
}
解决方案 »
- 求助一个c#界面绘制问题
- 演练:在 Windows 应用程序中创建一个用于搜索数据的窗体
- 没有为该对象定义无参数的构造函数。
- WinFrom 制作安装于卸载程序!
- 如何获得计算机的状态是已登录状态
- C#连接Oracle数据库, 提示"ORA-12154: TNS: 无法解析指定的连接标识符",怎么解决??
- C#类型转换问题
- 如何动态添加和原来groupbox中一模一样的控件
- <WinForm>ListView如何选择行(SelectedIndexChanged)时提问:“确定要移到此行?”,如回答“是”则选择所点击(或键盘选择)的行,如“
- 怎样不用水晶报表做发票的套打?
- 严重不爽,车丢了,散40分,快来哦!!!!
- ListBox怎么设成多Column的
Application.Exit()不会引发Form_Closing事件。C#里没办法判断是自己还是因为系统关闭而发送的关闭消息。我做过一个小程序,重载WndProc,在0x0010消息时作相关动作。
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case 0x0010: //WM_CLOSE
if(!_quitable)
{
HideMe();
return;
}
break;
default:
break;
}
base.WndProc(ref m);
}
{
if(((Form)sender).DialogResult==DialogResult.None)
{
e.Cancel=true;//重点是这e
this.Hide();
this.notifyIcon1.Visible=true;
}
}
{
if(((Form)sender).DialogResult==DialogResult.None)
{
e.Cancel=true;//重点是这e
this.Hide();
this.notifyIcon1.Visible=true;
}
}
protected override void WndProc(ref Message m )
{
if (m.WParam.ToInt32()== 0xF060) // 关闭消息
{
m.Result = new IntPtr(0); // Take care of message
this.WindowState = FormWindowState.Minimized;
}
else
base.WndProc(ref m); // ...let Form take care of this message (normally)
}
而系統關機或者強制終止這些動作都不會發送WM_CLOSE消息我一直都這麼用沒什麼問題.你用的0xF060(SC_CLOSE)