i am making a project in vb.net and i have a bio data form in it
i have 2 textbox in it, TextBox1 is for Name and the Textbox2 is for father's name . i want to make the first letters of Name in textBox1 as Capital(eg: Pratik Shukla) in both the TextBox .on focus lost

OK, you will need to use the UCase, and mid functions simply like this:

Function GetFormattedName AS String
dim FormattedName as string =""
dim FirstName as String =""
dim LastName as String =""

if trim(Textbox1.text) <> "" then
    Firstname  = trim(Textbox1.text)
end if
if trim(Textbox2.text) <> "" then
    Lastname  = trim(Textbox2.text)
end if

If Firstname <>"" then
    'Fully formatted Name   Uppercase First char    Lowercase the rest and add a space
    FormattedName = UCASE(mid(FirstName,1,1)) & lcase(mid(FirstName,2)) &" "
end if

If LastName <> "" then
    'Append last name in the correct format as above
    FormattedName = FormattedName  & UCASE(mid(LastName,1,1)) &lcase(mid(LastName,2))
End If

GetFormattedName = trim(FormattedName) 
'If we did not get any values we will get an empty string
'If we only got FirstName, the trim will strip out the trailing space.
End Function

You could use the TextChanged property of the textboxes. This code will change all first letters to upper case (ProperCase) as soon as text is put into your textboxes. Instead of ProperCase, UpperCase or Lowercase can also be used.

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged
        If TextBox1.Text <> "" Then
            Dim a As String = TextBox1.Text
            TextBox1.Text = (StrConv(a, VbStrConv.ProperCase))
            TextBox1.Select(TextBox1.Text.Length, 0)
        End If
        If TextBox2.Text <> "" Then
            Dim a As String = TextBox2.Text
            TextBox2.Text = (StrConv(a, VbStrConv.ProperCase))
            TextBox2.Select(TextBox2.Text.Length, 0)
        End If
    End Sub
Comments
+1 for the code
This article has been dead for over six months. Start a new discussion instead.