我可以使用 e.SuppressKeyPress = true 的組合鍵,但如果我需要 ALT LMB 例如,我如何使用 ALT 使其不激活選單?因為當按下 LMB 時,背景關系不再在 KeyDown 事件中。
uj5u.com熱心網友回復:
找到了一個解決方案,這很簡單:
- 在滑鼠事件回呼或覆寫中有一個標志,以告知是否使用了 ALT 并且需要抑制。
- 如果設定了標志,則在 KeyUp 回呼或覆寫中使用 ALT。單獨的 ALT 被檢測為 Keys.Menu 并且它僅在選單啟動時才激活選單。
以下是一些代碼片段:
bool suppressALT = false;
...
protected override void OnKeyUp(KeyEventArgs e)
{
// when ALT is finally up, suppress it
// if it was used by a mouse combo
if(e.KeyCode == Keys.Menu && suppressALT)
{
suppressALT = false; // clear flag so it won't suppress the menu forever
e.SuppressKeyPress = true;
}
base.OnKeyUp(e);
}
...
protected override void OnMouseDown(MouseEventArgs e)
{
...
// suppress ALT if mouse combo uses it
if((Control.ModifierKeys & Keys.Alt) == Keys.Alt)
suppressALT = true;
...
base.OnMouseDown(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
...
// suppress ALT if mouse combo uses it
if((Control.ModifierKeys & Keys.Alt) == Keys.Alt)
suppressALT = true;
...
base.OnMouseMove(e);
}
protected override void OnMouseWheel(MouseEventArgs e)
{
...
// suppress ALT if mouse combo uses it
if((Control.ModifierKeys & Keys.Alt) == Keys.Alt)
suppressALT = true;
...
base.OnMouseWheel(e);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/418017.html
標籤:
