当我在我的程序中按 F10 时,焦点从我的主程序窗口中消失,并移动到菜单栏。事实证明,这种奇怪的行为在许多 Windows 应用程序中很常见。
我认为这很丑陋,因为 Alt 键做同样的事情,我们失去了一个宝贵的功能键。为什么 Windows 会这样做,我该如何解决我的 C# 应用程序的问题?
最佳答案
为您的表单使用 KeyDown 事件,并处理击键:
private void form_KeyDown(object sender, KeyEventArgs e)
{ if(e.KeyData == Keys.F10)
{
// Do what you want with the F10 key
e.SuppressKeyPress = true;
}
}
还要确保您的表单 KeyPreview 设置为 true。
关于c# - 在 C# Winforms 程序中禁用 F10 键将焦点移动到菜单栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8116282/