Hi i have a conflict with a string
i want some words of a string to make lowercase
shal i have as string

Valkenburg Aan De Geul

But i want it to make it as

Valkenburg aan de Geul

the folowing code dos not work ang gives a conflict

 If TextBox1.Text.Contains("Aan De") = True Then
            Dim wordString As String = TextBox1.Text

            TextBox1.Text = Replace(wordString, "Aan De", "aan de")

ElseIf TextBox1.Text.Contains("Aan De") = False Then

            Dim x As TextBox = CType(sender, TextBox)
            Dim sel_Start As Integer
            Dim sel_Length As Integer

            sel_Start = x.SelectionStart
            sel_Length = x.SelectionLength
            x.Text = StrConv(x.Text, VbStrConv.ProperCase)
            x.SelectionStart = sel_Start
            x.SelectionLength = sel_Length

        End If

Can someone help me with some code i don't kmow how to fix it
Thanks in advice John

'add a button and a textbox

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

   MsgBox(TextBox1.Text.ToLower)

End Sub

You are using your type cast wrongly. Sender is a callback function:
http://stackoverflow.com/questions/11713250/vb-net-what-is-sender-used-for
Leave this out and you may use:

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If TextBox1.Text.Contains("Aan De") = True Then
            Dim wordString As String = TextBox1.Text
            TextBox1.Text = Replace(wordString, "Aan De", "aan de")
        ElseIf TextBox1.Text.Contains("Aan De") = False Then
            TextBox1.Text = StrConv(TextBox1.Text, VbStrConv.ProperCase)
        End If
    End Sub

i know it works on button click, but if it is possible i want it in
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
and all other words i need propercase
because it's a bit more beautiful
but if not possible i put it in buttonclick event
and then i have the following

  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim wordString As String = TextBox1.Text

        If wordString.Contains("Aan De") = True Then
            Dim newword As String = Replace(wordString, "Aan De", "aan de")
bla bla bla

elseIf wordString.Contains("Aan De") = false Then
bla bla bla
end if

end sub

 Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
  Dim x As TextBox = CType(sender, TextBox)
            Dim sel_Start As Integer
            Dim sel_Length As Integer

            sel_Start = x.SelectionStart
            sel_Length = x.SelectionLength
            x.Text = StrConv(x.Text, VbStrConv.ProperCase)
            x.SelectionStart = sel_Start
            x.SelectionLength = sel_Length

end sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        TextBox1.Text = StrConv(TextBox1.Text, VbStrConv.ProperCase)
        TextBox1.SelectionStart = TextBox1.Text.Length
End Sub
'I think this is what you want.

    Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
            If e.KeyCode <> Keys.Delete And e.KeyCode <> Keys.Back Then
                TextBox1.Text = StrConv(TextBox1.Text, VbStrConv.ProperCase)
                TextBox1.Text = Replace(TextBox1.Text, "Aan De", "aan de")
            End If
    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

            TextBox1.SelectionStart = TextBox1.Text.Length
    End Sub

hi Phoguez
that's almost as i want it only the first letter dosn't start with propercase
the first letter goes only to propercas when i type the second letter.
Thanks for so far

'instead of KeyDown i used KeyUp

    Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
        If e.KeyCode <> Keys.Delete And e.KeyCode <> Keys.Back Then
            TextBox1.Text = StrConv(TextBox1.Text, VbStrConv.ProperCase)
            TextBox1.Text = Replace(TextBox1.Text, "Aan De", "aan de")
        End If
    End Sub


    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

        TextBox1.SelectionStart = TextBox1.Text.Length
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.