英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论