简体   繁体   English

标签的按键事件

[英]Keydown Event of a Label

I have used a runtime draggable label in WPF which i found here . 我在WPF中使用了运行时可拖动标签,在这里可以找到。

I want to move this label on key up and down button. 我想在向上和向下按钮上移动此标签。 The problem is that label does not register key down or key up event. 问题在于标签没有注册按键按下或按键按下事件。 How to do this? 这个怎么做?

I was told here that i should disguise a textbox as a label but then the dragging facility disappears. 我在这里被告知,我应该将文本框伪装成标签,但是拖动工具消失了。 How to achieve label key down without disguise? 如何在不掩盖伪造的情况下实现标签键的降低?

You can move the label by this way- 您可以通过这种方式移动标签-

  1. Add Mouse down event to the label and give it focus- 将鼠标按下事件添加到标签,并使其具有焦点-

     private void label1_MouseDown(object sender, MouseButtonEventArgs e) { label1.Focus(); } 
  2. Set this property for this label- 为此标签设置此属性-

     Focusable="True" 

This way the label will respond to your key down event. 这样标签将响应您的按键事件。

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

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