在 GotFocus 事件中获取 KeyCode?
C# WinApps:有什么方法可以检查是否按下了 CTRL-V 之类的东西,但不在 KeyDown、PreviewKeyDown、KeyPress 等事件中?这些正在被我的应用程序中的其他部分占用,而且很难找到它们,所以我认为这个控件可以,让我们检查其 GotFocus 事件中按下的键!是否可以?
C# WinApps: Is there any way that I can check if something like CTRL-V is pressed but not in the KeyDown,PreviewKeyDown,KeyPress,etc ... events? those are being eaten by some other parts in my App and it is so hard to find them so I thought Ok for this contorl lets check the pressed keys in its GotFocus event! Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定事件被“吃掉”是什么意思。事件可以调用多个处理程序。因此,即使该事件已经被一个处理程序订阅,您也可以使用另一个处理程序订阅它,它应该可以正常工作。
另一种选择是对您正在使用的控件进行子类化并使用该子类。然后,您可以重写 On{event} 方法并用这些方法执行您想要的任何操作(请务必调用基方法以确保原始类的行为仍然存在)。
华泰
Not sure what you mean by the events being "eaten". Events can call multiple handlers. So even if the event is already being subscribed to by one handler, you can subscribe to it with another handler and it should work just fine.
Another option would be to subclass the control you are using and use the subclass instead. Then you can override the On{event} methods and do anything you want with those (be sure to call the base method as well to ensure the behavior of the original class is still in place).
HTH