'仅供参考Option ExplicitPrivate Declare Function SetParent Lib "user32" _ (ByVal hWndChild As Long, _ ByVal hWndNewParent As Long) As Long Private Declare Function GetCaretPos Lib "user32" _ (lpPoint As POINTAPI) As Long
Private Type POINTAPI x As Long y As Long End TypePrivate Sub Form_Load() SetParent Command1.hWnd, RichTextBox1.hWnd End SubPrivate Sub RichTextBox1_SelChange() Dim pt As POINTAPI Call GetCaretPos(pt) Command1.Left = pt.x * Screen.TwipsPerPixelX + 30 Command1.Top = pt.y * Screen.TwipsPerPixelY End SubPrivate Sub Command1_Click() MsgBox "OK" End Sub
(ByVal hWndChild As Long, _
ByVal hWndNewParent As Long) As Long
Private Declare Function GetCaretPos Lib "user32" _
(lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End TypePrivate Sub Form_Load()
SetParent Command1.hWnd, RichTextBox1.hWnd
End SubPrivate Sub RichTextBox1_SelChange()
Dim pt As POINTAPI
Call GetCaretPos(pt)
Command1.Left = pt.x * Screen.TwipsPerPixelX + 30
Command1.Top = pt.y * Screen.TwipsPerPixelY
End SubPrivate Sub Command1_Click()
MsgBox "OK"
End Sub