如何将焦点从按钮上移除

huangapple go评论65阅读模式
英文:

How to remove focus from a button

问题

我有一个面板上有一个按钮。但有一个问题。我需要使用KeyEventHandler来捕获Enter键的按下,按钮被按下,但事件未被处理。我尝试过手动将焦点设置到表单,但没有帮助。如果我不添加按钮,一切都正常工作。你能告诉我如何解决这个问题吗?

我创建了一个新项目并尝试过:有按钮时,事件不被调用,按钮被按下;没有按钮时,事件被调用。

英文:

I have a panel on which there is a button.But there is a problem. I need to use KeyEventHandler to catch the Enter press, the button is pressing, and the event is not processed. I tried artificially giving focus to Form, but it didn't help.If I don't add buttons, everything works fine. Can you tell me how to solve this?

I created a new project and tried: with the button, the Event is not called, and the button is pressed, without the button, the event is called.

答案1

得分: 0

你需要启用该窗体的 KeyPreview 属性,以捕获 KeyEventHandler。同时检查你的 AcceptButton 属性是否设置正确。

英文:

you need to enable KeyPreview property of that form, to catch a KeyEventHandler. Also check that your AcceptButton property has correct value

huangapple
  • 本文由 发表于 2023年2月19日 18:31:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75499477.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定