CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Stuck again!

  1. #1
    Join Date
    Mar 2001
    Posts
    6

    Stuck again!

    I am stuck again! Can anyone help me with this... I am looking for a way in VB to tell me what position the cursor is at in a textbox. Can I do it through the KeyPress event? If so, can somone help me?


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Stuck again!

    The Keypress event won't do, for 2 reasons:
    1) the keypress event involkes before the character is actually added to the text
    2) the keypress event wont fire when you press the arrow buttons

    An alternative is the Keyup event. When the event fires, check for the selstart property.

    Also make sure to do the same in the click event


    private Sub Text1_Click()

    Label1.Caption = Text1.SelStart

    End Sub

    private Sub Text1_KeyUp(KeyCode as Integer, Shift as Integer)

    Label1.Caption = Text1.SelStart

    End Sub




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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

Featured