CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 1999
    Posts
    102

    positioning a control at caret position in a reach text box - mdi app - help...

    Hi all,
    I need help with positioning a list box in a rich text box at the caret position.
    The text box is in a from which is a member of an mdi form app.
    In order to position the list box at the caret position, at first, I just used the GetCaretPos func and used the caret
    Position strait to the list box top and left - but it didn't appear at the caret position - at all!
    So, as someone suggested here, I transferred the caret position with ClienToScreen func to General screen coordinates, and tried to use these coordinates on the list box but still - the list box position will shift progrecively as the carets position will shift.
    Can someone please give me some more detailed pointers to what I might be doing wrong - or that I didn't thougth of?…
    Code samples will be appreciated - even very simplified…
    Here is what I did - schematically…

    Thanks In advance...

    Dim Caretpos as POINTAPI
    Dim Pos&
    Pos = GetCaretPos form.whnd, Caretpos
    ClientTosCreen Caretpos
    List1.left = Caretpos.x
    List1.top = Caretpos.y



  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: positioning a control at caret position in a reach text box - mdi app - help...

    You need to Convert the Coords to Screen Coords, then Back to the Form Coords, eg.


    private Type POINTAPI
    X as Long
    Y as Long
    End Type

    private Declare Function GetCaretPos Lib "user32" (lpPoint as POINTAPI) as Long
    private Declare Function ClientToScreen Lib "user32" (byval hwnd as Long, lpPoint as POINTAPI) as Long
    private Declare Function ScreenToClient Lib "user32" (byval hwnd as Long, lpPoint as POINTAPI) as Long

    private Sub RichTextBox1_DblClick()
    Dim tCaret as POINTAPI
    Call GetCaretPos(tCaret) 'get the Caret Position in RichTextbox Coords
    Call ClientToScreen(RichTextBox1.hwnd, tCaret) 'get the Coords in Screen Coords
    Call ScreenToClient(hwnd, tCaret) 'get the Coords in Form Coords
    List1.Move ScaleX(tCaret.X + 3, vbPixels, vbTwips), ScaleY(tCaret.Y, vbPixels, vbTwips)
    End Sub





    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

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