Sub SelectAll(TheControl As TextBox)
TheControl.SelStart = 1
TheControl.SelLength = Len(TheControl)
TheControl.SetFocus
End SubPrivate Sub Text1_GotFocus()
SelectAll (Text1)
End Sub
//功能很简单,就是让text得到焦点时全选取text1.text
TheControl.SelStart = 1
TheControl.SelLength = Len(TheControl)
TheControl.SetFocus
End SubPrivate Sub Text1_GotFocus()
SelectAll (Text1)
End Sub
//功能很简单,就是让text得到焦点时全选取text1.text
SendKeys "{HOME}" + "+{END}"
End Sub
SelectAll Text1
TheControl.SelStart = 0
TheControl.SelLength = Len(TheControl)
TheControl.SetFocus
End SubPrivate Sub Text1_GotFocus()
SelectAll Text1
End Sub
TheControl.SelStart = 0 '这个应该从零开始,而不是1
TheControl.SelLength = Len(TheControl)
TheControl.SetFocus
End SubPrivate Sub Text1_GotFocus()
Call SelectAll(Text1) '调用的时候如果没有返回值,可以不用括号,或者用CALL
End Sub
TheControl.SelStart = 0
TheControl.SelLength = Len(TheControl)
TheControl.SetFocus
End SubPrivate Sub Text1_GotFocus()
SelectAll (Me.Controls("text1"))
End Sub
如Name为Text1的TextBox:
名字Text1也可等价于Text1.text——String类型数据
当然也可作为控件名Text1——Controls对象型数据
on error resume next
TheControl.SetFocus
TheControl.SelStart = 0
TheControl.SelLength = Len(TheControl)
End SubPrivate Sub Text1_GotFocus()
call SelectAll (Text1)
End Sub