Home >Backend Development >PHP Tutorial >Example of customizing shortcut keys in C# WinForm, _PHP tutorial
Download the source code of this article: http://xiazai.jb51.net/201501/tools/cs-key-setting.rar
During the project development process, it is necessary to implement the custom shortcut key function in the software settings similar to Youdao Dictionary, as shown in the figure below:
When we press Ctrl+Alt+M one after another, the software will automatically display the shortcut keys in the text box.
The final effect is as shown below:
The core code is as follows:
private void keyUp(object sender, KeyEventArgs e)
{
String str = this.ActiveControl.Text.TrimEnd();
int len = str.Length;
If (len >= 1 && str.Substring(str.Length - 1) == "+")
{
This.ActiveControl.Text = "";
}
}
Correspondence between e.KeyValue and characters
字符 | e.KeyValue |
a-z|A-Z | 65-90 |
F1-F12 | 112-123 |
0-9 | 48-57 |
PageUp | 33 |
PageDown | 34 |
End | 35 |
Home | 36 |
左(←) | 37 |
上( ↑ ) | 38 |
右(→) | 39 |
下( ↓ ) | 40 |
Next, set the _KeyDown and _KeyUp events for the textbox control respectively, and call the above two core functions in them.
As shown below:
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
KeyUp(sender, e);
}