Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim ch As Char = e.KeyChar
If Not Regex.IsMatch(ch.ToString(), "^[\b\r0-9a-fA-F]$") Then
e.KeyChar = "" '放弃输入的非法字符
MessageBox.Show("请正确输入16进制数!!!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
e.KeyChar = Char.ToUpper(ch) '强制转换为大写字母,放过退格和回车符
End If
End Sub
文章评论(0条评论)
登录后参与讨论