受按钮影响的按键事件
我是新来的,我在使用 C# 应用程序时遇到了一些问题。 我想捕获按键按下事件。 一开始这不是问题,但在我向表单添加一些按钮后,表单的按键事件会忽略箭头键并将焦点从一个按钮移动到下一个按钮。(按键事件有效)是否有当我按住箭头键时如何阻止这个并让他们做其他事情?
I'm new around here and i have a little problems with a C# application.
I want to capture the key down event. This wasn't a problem at first but after i added some buttons to the form, the key down event of the form ignores the arrow keys and moves the focus from one button to the next.(The key up event works) Is there a way to stop this and make them do something else when i hold the arrow keys?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置 KeyPreview 属性在表单上设置为 true。 这将允许表单除了子控件之外还可以看到 keydown 事件。将其添加到您的表单中...
Set the KeyPreview property on the Form to true. That will allow the form to see the keydown event in addition to the child controls.Add this to your Form ...
如果您不希望控件具有正常的按键功能,则需要在每个控件上设置按键事件,并将事件参数的handled属性设置为true,这样它就不会冒泡到内置控制功能。
If you don't want the normal key down functionality for the controls you will need to set the key down event on each control, and set the handled attribute for the event arguments to be true, that way it doesn't bubble up to the built in control functionality.