Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged Dim txtBox As TextBox = DirectCast(sender, TextBox) If txtBox.Text.Length = 0 Then Return With txtBox Dim debutSelection As Integer = .SelectionStart Dim longueurSelection As Integer = .SelectionLength .Text = .Text.Substring(0, 1).ToUpper + .Text.Substring(1).ToLower .SelectionStart = debutSelection .SelectionLength = longueurSelection End With End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Function EpureNom(ByVal ctrlTbx As TextBox, ByVal nomEntre As String) As String '*** Utilisation de "Substring" qui permet de récupérer une sous-chaîne de cette instance. ' La sous-chaîne démarre à une position de caractère spécifiée et a une longueur définie. ' La sous-chaîne démarre à une position de caractère spécifiée. nomEntre = nomEntre.Substring(0, 1).ToUpper(Globalization.CultureInfo.CurrentCulture) & _ nomEntre.Substring(1).ToLower(Globalization.CultureInfo.CurrentCulture) Return nomEntre End Function
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) _ Handles TextBox1.Validating TextBox1.Text = EpureNom(TextBox1, TextBox1.Text) End Sub
ctrlTbx.Text = "" ctrlTbx.Focus() Return ""