Results 1 to 4 of 4

Thread: VB.NET Proper Case

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Pilipinas
    Posts
    441

    VB.NET Proper Case

    I use this code so that the text of the TextBox1 will change to Proper Case;

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    TextBox1.Text = StrConv(TextBox1.Text, VbStrConv.ProperCase)
    SendKeys.Send("{End}")
    End Sub

    But the problem of this code, When I type "HELLO" and i will going to erase "E" using backspace, the cursor goes to the end (at the right side of O).
    Anybody has a better idea for this?

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    You could check what the key pressed was. So if it was backspace, or any other special key, then don't go to end.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Sorry, I can't see the problem. You can place the cursor where you want by using the cursorleft and cursor right keys or the mouse. Obviously, the moment you delete a character you fire the TextChanged event and your proper case routine re-writes the textbox.text.

    Where do you want the cursor to finish?

    By the way, I had to use
    VB Code:
    1. SendKeys.SendWait("{End}")
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  4. #4
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    I have hardly fighted with real time control of input in textbox and I know that put cursor where you want to find it, is not an easy thing. Anyway, basically you have to acquire cursor position:

    Dim SS as byte
    SS=Textbox1.SelectionStart

    then you have to calculate where it have to finish after changing is done, modify SS, and put it there with code like this

    TextBox1.SelectionStart=SS

    Good luck!

    Live long and prosper (Mr. Spock)

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