Results 1 to 13 of 13

Thread: Cursor position!!!

  1. #1
    Seth DK
    Guest

    Exclamation Cursor position!!!

    Is there any way you can determine the postition of the cursor in a multi-line scrolling RichText box??

    I will need this knowledge to make an AutoCompleter for my text editor program!!

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    If you mean the position of the caret then use SelStart property.

  3. #3
    Seth DK
    Guest

    Not what I mean

    I am looking for somehow to determine the exact position of the cursor in fx. pixels (x,y)

    I will make a drop-down code-completer a little like the one in the VB editor when you press CTRL+SPACE...

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Are you talking about the mouse cursor or the text caret?

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    I will assume it's the text caret you are talking about.
    Then use the GetCaretPos API function:
    VB Code:
    1. Private Declare Function GetCaretPos _
    2.  Lib "user32" (lpPoint As POINTAPI) As Long
    3.  
    4. Public Type POINTAPI
    5.     x As Long
    6.     y As Long
    7. End Type
    You call it like this:
    VB Code:
    1. Dim p As POINTAPI
    2. RichTextBox1.SetFocus
    3. If GetCaretPos(p) Then
    4.     MsgBox "The caret is at " & p.x & ", " & p.y
    5. End If
    Best regards

  6. #6
    Seth DK
    Guest

    The text caret...!

    The text caret...!

    If I for instance in the RichText field type "Ap" and activate some shortcut a drop-down list with suggestons like "Application" appear right below the text caret... The problem is to locate that exact spot...

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: The text caret...!

    Originally posted by Seth DK
    The text caret...!

    If I for instance in the RichText field type "Ap" and activate some shortcut a drop-down list with suggestons like "Application" appear right below the text caret... The problem is to locate that exact spot...
    Now you're making me confused. Didn't you read my last post in this thread?
    Use the GetCaretPos API function.

  8. #8
    Seth DK
    Guest

    Oops

    Sorry about that!!

    We must have been posting at the same time...lol

    Thanks!

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Oops

    Originally posted by Seth DK
    Sorry about that!!

    We must have been posting at the same time...lol

    Thanks!
    Yeah, well you danish people is much like the people form Norway (yes, I'm talking about you peet ) a bit slow

  10. #10
    Seth DK
    Guest

    Still having problems...

    I have experimented with it for some time now, and I can now (thanks to your help) locate the text caret in a text box, but what exactly do I do to the data I get??

    It seems it is neither Pixels, nor Twips the numbers are formatted to.

    I can make the drop-down list move - also in the correct direction, but it does not follow the cursor - it is moving "slower"

    PLEASE ADVICE :-(

  11. #11
    Lively Member
    Join Date
    Aug 2001
    Location
    Crossroads of America
    Posts
    72
    Multiplying the x,y coordinates of the point type by 15 appears to give pixels. Anyone know why?

  12. #12
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    According to the MSDN Library:
    The GetCaretPos function copies the caret's position, in client coordinates, to the specified POINT structure.
    Client coordinates should be whatever you've set the ScaleMode to.
    Originally posted by DaveAMS
    Multiplying the x,y coordinates of the point type by 15 appears to give pixels. Anyone know why?
    Screen.TwipsPerPixelX and Screen.TwipsPerPixelY equals 15.

  13. #13
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Exclamation Ehh ? Twios, howto ?

    How do i get the posistion in the vb twips ?? What should i multiply/devide with ? please help !

    Regards
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

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