Value Name = Notepad Value Data = c:\windows\notepad.exe
在 TextBox 中如何限制只能输入数字
参考下列程序:
Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0 End If End Sub
TextBox 中能不接受某些特定字符(如 '@#$%")
方法有好几种, 以下列举二种:
方法1: 可以使用 IF 或 Select Case 一个个判断, 但如果不接受的字符多时, 较麻烦!
方法2: 将要剔除的字符统统放在一个字串中,只要一个 IF 判断即可 !! 如下:
Private Sub Text1_KeyPress(KeyAscii As Integer) Dim sTemplate As String sTemplate = "!@#$%^&*()_+-=" '用来存放不接受的字符 If InStr(1, sTemplate, Chr(KeyAscii)) > 0 Then KeyAscii = 0 End If End Sub
如何让鼠标进入 TextBox 时自动选定 TextBox 中之整串文字
这个自动选定反白整串文字的动作,会使得输入的资料完全取代之前在 TextBox 中的所有字符。
Private Sub Text1_GotFocus() Text1.SelStart = 0 Text1.SelLength = Len(Text1) End Sub
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long