In C/S
In the WinForm program, if you want to allow a text box to only enter numbers or letters, you can only enter the following methods ('\ B means: Delete the key ungemb '):
Only letters can be entered
Private void textBox2_KeyPress (object sender, KeyPressEventArgs e)
{
// Whether to process the event. If it is true, the event will be processed; otherwise, the event will not be processed.
E. Handled = true;
If (e. keyChar> = 'A' | e. keyChar> = 'A') & (e. keyChar <= 'Z' | e. keyChar <= 'Z') | e. keyChar = '\ B ')
{
E. Handled = false;
}
}
Only numbers can be entered
Private void textBox1_KeyPress (object sender, KeyPressEventArgs e)
{
E. Handled = true;
If (e. KeyChar> = '0' & e. KeyChar <= '9' | e. KeyChar = '\ B ')
{
E. Handled = false;
}
}
Method for rewriting in WINFORM: ProcessCmdKey can obtain keyboard keys
Protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
{
Const int WM_KEYDOWN = 0X100;
Const int WM_SYSKEYDOWN = 0X104;
String strInfo = string. Empty;
If (msg. Msg = WM_KEYDOWN) | (msg. Msg = WM_SYSKEYDOWN ))
{
Switch (keyData)
{
Case Keys. Down:
StrInfo = "down ";
Break;
Case Keys. Up:
StrInfo = "up ";
Break;
Case Keys. Left:
StrInfo = "Left ";
Break;
Case Keys. Right:
StrInfo = "right ";
Break;
}
}
Return base. ProcessCmdKey (ref msg, keyData );
}
In B/S
In. aspx, you can only enter numbers as follows:
1. Verify using the JS method
2. Use Keyboard Events (also JS)
<Input onkeypress = "if (event. keyCode> = 48 & event. keyCode <= 57) {event. returnValue = true;} else {event. returnValue = false;} "/>
In. aspx, you can only enter letters as follows:
1. Verify using the JS method
2. Use Keyboard Events (uppercase letters: 65-90, lowercase letters: 97-122)
<Input onkeypress = "if (event. keyCode> = 65 & event. keyCode <= 90) | (event. keyCode> = 97 & event. keyCode <= 122) {event. returnValue = true;} else {event. keyCode = false;} "/>
Input Method of the shielded text box: style = "ime-mode: disabled"
How to remove the dotted line on the button when the button is pressed: hidefocus = "false"
From happy pig's column