【发布时间】:2019-07-01 07:21:26
【问题描述】:
我已重写 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);
但是什么也没发生。
【问题讨论】:
-
消息框可能是解决所有问题的关键
-
您是否尝试过设置 KeyPreview 属性 = true 并管理 keyPress 事件来调整 WndProc?
-
Keypreiew 的问题是关联的 from 必须打开才能工作。如果表单被最小化或未选择它就不起作用。但我需要一个与中断服务程序配合使用的热键。
-
你为 e.Cancel 设置了什么?
-
在 OnClosingForm 方法的主体中我设置了 'e.Cancel=false'