Results 1 to 4 of 4

Thread: [RESOLVED] Cursor position within rich text box

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    28

    Resolved [RESOLVED] Cursor position within rich text box

    Hello,

    I there a way to obtain the (x,y) position of a word within a rich text box? For example, within the RTB, there is the phrase:

    I can walk a mile.

    Can I obtain the cursor position just before the letter 'w' in the word 'walk'?

    Thanks.

  2. #2
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Cursor position within rich text box

    You can easily get the mouse position inside a textbox by simply using:

    VB Code:
    1. Private Sub RichTextBox1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)

    The x and y values returned is the position of the pointer inside the textbox, not the form. As for character positions you can get the y value for a line easily enough, but because characters are different widths, you can't get the x value, i don't think, unless you were willing to move along the line one character at a time and add up the width, though that would mean finding the width of every character and using a select case.
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    28

    Re: Cursor position within rich text box

    Kazar,

    Thanks for the reply.

    The strings within the RTB are bing fed by the application, so Mousemove doesn't come into play. I did consider the idea of building a table of character widths, but screen resolutions will affect that on different users' terminals.

  4. #4
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Cursor position within rich text box

    you can get the screen res i think and use that as a multiplier
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

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