简体   繁体   English

如何捕获标签的keydown事件?

[英]How to Capture keydown event of a Label?

I added the event, I click in the label and press any key, but it doest go to the method. 我添加了事件,我单击标签并按任意键,但是它没有转到该方法。 How can I capture? 我该如何捕捉?

I don't think labels can receive keyboard input. 我认为标签无法接收键盘输入。 It will go to the control with focus, and labels can never have focus (by default, I guess you might pull some shenanigans though), most likely your events are going to your main form. 它将以焦点移到控件上,标签永远不会有焦点(默认情况下,我猜您可能会拉扯一些假名),很有可能事件将以您的主要形式出现。

也许您可以伪装成看起来像标签的文本框。

To add content beyond my other comment. 添加除我的其他评论之外的内容。 Have you looked at something like input bindings for what you are trying to do? 您是否正在尝试输入绑定之类的东西?

http://msdn.microsoft.com/en-us/library/system.windows.input.inputbinding.aspx http://msdn.microsoft.com/en-us/library/system.windows.input.inputbinding.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM