我已经重写了wndproc()以使用热键。但表格将不再关闭。然后关闭程序,使程序陷入wndproc()的无限循环中。
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0x0312)
{
Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
int id = m.WParam.ToInt32();
MessageBox.Show("Hotkey has been pressed!");
// do something
}
}
我已将e.cancel设置为true,并在OnFoemClosing方法`
中添加了以下代码 e.Cancel = false;
base.OnFormClosing(e);
但是什么也没发生。
答案 0 :(得分:-1)
[DllImport("user32.dll")]
static extern bool DestroyWindow(IntPtr hWnd);
//Closes the form
btnCloseWindow_Click(object sender, EventArgs e)
{
DestroyWindow(this.Handle);
}`[DllImport("user32.dll")]
static extern bool DestroyWindow(IntPtr hWnd);
//Closes the form
btnCloseWindow_Click(object sender, EventArgs e)
{
DestroyWindow(this.Handle);
}`