有時(shí)我們想在textbox控件獲得焦點(diǎn)時(shí)而選中textbox中的所有文本,這可通過SelStart和SelLength屬性來(lái)達(dá)到。具體來(lái)講就是在對(duì)象得到焦點(diǎn)時(shí),從最前面開始選取(SelStart=0),選取的長(zhǎng)度為文本長(zhǎng)度(Len(Text1)),源代碼如下:
Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End Sub
GotFocus事件是在控件獲得焦點(diǎn)時(shí)發(fā)生。
新聞熱點(diǎn)
疑難解答