Click to See Complete Forum and Search --> : positioning a control at caret position in a reach text box - mdi app - help...


mikledet
September 30th, 1999, 04:57 PM
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

Aaron Young
October 6th, 1999, 03:38 PM
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
adyoung@win.bright.net
aarony@redwingsoftware.com