限制TextBox只允许输入数字和字母

设置TextBox控件属性

ImeMode=Disable
ShortcutsEnabled=False

  

VB.NET

 Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
       If e.KeyCode = Keys.Space Then e.SuppressKeyPress = True
    End Sub

C#

private void TextBox1_KeyDown(object sender, KeyEventArgs e)
{
	if (e.KeyCode == Keys.Space)
	e.SuppressKeyPress = true;

}

  

猜你喜欢

转载自www.cnblogs.com/dylike/p/10487223.html