Selezionare tutto il testo all'interno di una TextBox, o di un altro controllo
Per selezionare tutto il testo contenuto all'interno di una casella di testo possiamo utilizzare 2 metodi.
1° Metodo:
Public Sub SelTesto()
If TypeOf Screen.ActiveControl Is TextBox Or TypeOf Screen.ActiveControl Is ComboBox Then
Screen.ActiveControl.SelStart = 0
Screen.ActiveControl.SelLength = Len(Screen.ActiveControl.Text)
End If
End Sub
Testato su: Windows 98, Windows Me, Windows 2000 Professional
2° Metodo:
Public Sub SelTesto2(CasellaTesto As Object)
CasellaTesto.SelStart = 0
CasellaTesto.SelLength = Len(CasellaTesto.Text)
If CasellaTesto.Visible = True And CasellaTesto.Enabled = True Then
CasellaTesto.SetFocus
End If
End Sub
Testato su: Windows 98, Windows Me, Windows 2000 Professional
3° Metodo:
Public Sub SelectAll(Editctr As Control)
With Editctr
.SelStart = 0
.SelLength = Len(Editctr.Text)
.SetFocus
End With
End Sub
nell'evento GotFocus event di un controllo di input, inserisci il seguente codice:
Call SelectAll(nomecontrollo)
Testato su: Windows 98, Windows Me, Windows 2000 Professional