If you dont know Propercase "(first char of a word is Upercase --> Visual Basic Is Easy)"
Hi i have an old Propercase function in VB6, but i cant apply in Vb.Net
This function changes to Propercase in realtime when i write text in the textbox using the keypress.
here is the VB6 way:
And in the Keypress event of a TextboxVB Code:
Public Function Txtmayus(Texto As TextBox, KeyAscii As Integer) ' SI EL PRIMER CARACTER ES UN ESPACIO If Len(Texto) = 0 Then If KeyAscii = 32 Then ' CANCELAR KeyAscii = 0 Exit Function End If End If ' SI NO ES EL 1° CARACTER If Texto.SelStart <> 0 Then ' DESPUES DEL ESPACIO NO If Mid$(Texto.Text, Texto.SelStart, 1) <> " " Then ' NO MAS DE 2 ESPACIOS CONSECUTIVOS If KeyAscii = 32 Then KeyAscii = 0 End If End If KeyAscii = Asc(UCase$(Chr$(KeyAscii))) End Function
But in .Net the e.KeyChar is read only and i cant asign a value, and if i useVB Code:
Txtmayus(Text1, Keyascii)
Texto.Text = StrConv(Texto.Text, VbStrConv.ProperCase) it reverses the chars.
Here is my VB.net code
And i try to use SendKeys.send but the app Blocks, hangVB Code:
' Permito solo Caracteres Public Sub TxtMayus(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Dim Texto As TextBox = CType(sender, TextBox) ' Si el primer caracter es un espacio If Len(Texto.Text) = 0 Then If Asc(e.KeyChar) = 32 Then ' Lo anulo e.Handled = True Exit Sub End If End If ' Si no es el 1° caracter If Texto.SelectionStart <> 0 Then ' Despues del espacio no If Mid(Texto.Text, Texto.SelectionStart, 1) = " " Then ' No mas de 2 espacios consecutivos If Asc(e.KeyChar) = 32 Then e.Handled = True Exit Sub End If End If End If Texto.Text = StrConv(Texto.Text, VbStrConv.ProperCase) End Sub![]()
VB Code:
e.Handled = True SendKeys.Send(e.KeyChar.ToUpper(e.KeyChar))
Any idea??![]()




Reply With Quote