如何防止用户控件表单在 C# 中处理键盘输入(箭头键)
我的用户控件包含可以选择的其他控件,我想实现使用箭头键在子控件上导航的方法
问题是父控件拦截箭头键并使用它来滚动其视图我想避免的事情是什么。我想自己解决控制内容的导航问题。
我如何控制由箭头键引起的标准行为?
提前致谢 MTH
my usercontrol contains other controls that can be selected, i would like to implement way of navigating over child controls with arrow keys
The problem is that parent controll intercepts arrow keys and use it to scroll its view what is the thing i want to avoid. I want to solve navigating over contents of control by myself.
How i can take control over standard behaviour that is caused by arrow keys?
Thanks in advance
MTH
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这通常是通过重写 IsInputKey() 方法来告诉您需要这些键来完成的。然而,这对 UserControl 不起作用,它永远不会获得焦点,因此 OnKeyDown 方法永远不会运行。相反,重写 ProcessCmdKey() 方法,该方法在表单看到击键之前调用。像这样:
This is normally done by overriding IsInputKey() method to tell that you want these keys. That however won't work for a UserControl, it never gets the focus so the OnKeyDown method never runs. Instead, override the ProcessCmdKey() method, it is called before the form sees the keystroke. Like this:
您可以在用户控件中重写 OnKeyDown,但这对于箭头键不起作用,因为它们不是“输入键”(它们是导航键)。
要更改行为,请覆盖 IsInputKey() 以告诉系统您想要获取箭头键事件:
You can override OnKeyDown in your user control, but that doesn't work for arrow keys because they are not 'input keys' (they are navigation keys).
To change the behaviour, override IsInputKey() to tell the system you want to get events for arrow keys: