Results 1 to 5 of 5

Thread: RESOLVED How to use Propercase?

Threaded View

  1. #1

    Thread Starter
    Addicted Member Sanko's Avatar
    Join Date
    Mar 2000
    Location
    Argentina
    Posts
    128

    Resolved RESOLVED How to use Propercase?

    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:
    VB Code:
    1. Public Function Txtmayus(Texto As TextBox, KeyAscii As Integer)
    2. ' SI EL PRIMER CARACTER ES UN ESPACIO
    3. If Len(Texto) = 0 Then
    4.     If KeyAscii = 32 Then
    5.         ' CANCELAR
    6.         KeyAscii = 0
    7.         Exit Function
    8.     End If
    9. End If
    10. ' SI NO ES EL 1° CARACTER
    11. If Texto.SelStart <> 0 Then
    12.     ' DESPUES DEL ESPACIO NO
    13.     If Mid$(Texto.Text, Texto.SelStart, 1) <> " " Then
    14.         ' NO MAS DE 2 ESPACIOS CONSECUTIVOS
    15.         If KeyAscii = 32 Then KeyAscii = 0
    16.     End If
    17. End If
    18. KeyAscii = Asc(UCase$(Chr$(KeyAscii)))
    19. End Function
    And in the Keypress event of a Textbox
    VB Code:
    1. Txtmayus(Text1, Keyascii)
    But in .Net the e.KeyChar is read only and i cant asign a value, and if i use
    Texto.Text = StrConv(Texto.Text, VbStrConv.ProperCase) it reverses the chars.

    Here is my VB.net code
    VB Code:
    1. ' Permito solo Caracteres
    2.     Public Sub TxtMayus(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
    3.         Dim Texto As TextBox = CType(sender, TextBox)
    4.  
    5.              ' Si el primer caracter es un espacio
    6.         If Len(Texto.Text) = 0 Then
    7.             If Asc(e.KeyChar) = 32 Then
    8.                 ' Lo anulo
    9.                 e.Handled = True
    10.                 Exit Sub
    11.             End If
    12.         End If
    13.         ' Si no es el 1° caracter
    14.         If Texto.SelectionStart <> 0 Then
    15.             ' Despues del espacio no            
    16.             If Mid(Texto.Text, Texto.SelectionStart, 1) = " " Then
    17.                 ' No mas de 2 espacios consecutivos
    18.                 If Asc(e.KeyChar) = 32 Then
    19.                     e.Handled = True
    20.                     Exit Sub
    21.                 End If
    22.             End If
    23.         End If
    24.         Texto.Text = StrConv(Texto.Text, VbStrConv.ProperCase)
    25.     End Sub
    And i try to use SendKeys.send but the app Blocks, hang
    VB Code:
    1. e.Handled = True
    2. SendKeys.Send(e.KeyChar.ToUpper(e.KeyChar))

    Any idea??
    Last edited by Sanko; Sep 27th, 2005 at 09:03 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width