The WPF TextBox Control obtains the hotkey and converts it to win32 Keys and wpftextbox.
The Key object used in WPF is different from the Keys in WinForm. The Key enumeration objects of the two are different from those of the physical Key, and the type cannot be forcibly converted. When you use the win api to register a hot Key, you need to convert it to a win32 Key value. You can use KeyInterop. VirtualKeyFromKey (). In addition, Keys can save the combined Keys, while Keys are only a single Key. The Keys member has a Modifiers, which can be seen from 0 ~ It is used to store function keys except 15 characters. From the comparison of the two images, You can intuitively find the difference between the two.
Sample Code:
using System.Windows.Input;namespace demo.Controls{ class HotKeyTextBox : BeiLiNu.Ui.Controls.WPF.Controls.XTextBox { private System.Windows.Forms.Keys pressedKeys = System.Windows.Forms.Keys.None; protected override void OnPreviewKeyDown(System.Windows.Input.KeyEventArgs e) { int keyValue = KeyInterop.VirtualKeyFromKey(e.Key); if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { keyValue += (int)System.Windows.Forms.Keys.Control; } if ((Keyboard.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt) { keyValue += (int)System.Windows.Forms.Keys.Alt; } if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) { keyValue += (int)System.Windows.Forms.Keys.Shift; } this.Keys = (System.Windows.Forms.Keys) keyValue; e.Handled = true; } public System.Windows.Forms.Keys Keys { get { return pressedKeys; } set { pressedKeys = value; setText(value); } } private void setText(System.Windows.Forms.Keys keys) { this.Text = keys.ToString(); } }}
WPF handles textbox style issues, click to get the focus background color change, when you click other places of the form (non-control), textbox automatically
The changes in the background color can be written in the IsFocused event.
After the input is complete, the textBox loses focus. You can receive the press ENTER event and the focus loss event in the textbox, and transfer the focus to other elements.
For example
Grid. IsFocusable = true;
Grid. GetFocus ();
Grid. IsFocusable = false;
Right-aligned Text attributes of TextBox controls in WPF
TextAlignment = "Left"