7,759
社区成员
发帖
与我相关
我的任务
分享
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If (e.KeyChar >= "0" And e.KeyChar <= "9") Or Asc(e.KeyChar) = 8 Then
TextBox1.ReadOnly = False
Else
TextBox1.BackColor = Color.White
TextBox1.ReadOnly = True
End If
End Sub
'以下为VB6的代码,当控件text1失去焦点时判断是否为数值型并取整
privte text1_lostfocus()
if text1.text="" then
msgbox "请输入数据!",48,"提示"
text1.setfocus
exit sub
else
if not isnumeric(text1.text) then
msgbox "请输入数值型数据!",48,"提示"
text1.setfocus
exit sub
else
text1.text=int(text1.text)
end if
end if
end sub