How to insert shape in cursor position when user clicks

五迷三道 提交于 2020-01-22 03:57:05

问题


I am trying to insert a shape in a position of cursor where user click by an event WindowBeforeDoubleClick, but when I use the code below its relate to screen coordinate so it is not placing in word page properly.

can anyone suggest how to find the page margin coordinate or any other in order to place the shape at cursor point in word.

This is the code

Public Sub addWin()

ActiveDocument.Shapes.AddShape(msoShapeRectangle, MouseX, MouseY, 20#, _
16#).Select
Selection.ShapeRange.Name = "WK# " & 2
Selection.ShapeRange.TextFrame.TextRange.Select
Selection.Collapse
Selection.Font.Name = "Arial"
Selection.Font.Size = 7
Selection.Font.Bold = False
Selection.Paragraphs.FirstLineIndent = 0
Selection.Paragraphs.RightIndent = -10
Selection.Paragraphs.LeftIndent = -10
Selection.Paragraphs.Alignment = wdAlignParagraphCenter
Selection.TypeText Text:=2
Selection.ShapeRange.LockAspectRatio = msoCTrue
 End Sub

Function MouseX(Optional ByVal hWnd As Long) As Long
Dim lpPoint As POINTAPI
GetCursorPos lpPoint
If hWnd Then ScreenToClient hWnd, lpPoint
MouseX = lpPoint.x
End Function

Function MouseY(Optional ByVal hWnd As Long) As Long
    Dim lpPoint As POINTAPI
    GetCursorPos lpPoint
    If hWnd Then ScreenToClient hWnd, lpPoint
    MouseY = lpPoint.y
End Function

来源:https://stackoverflow.com/questions/59402917/how-to-insert-shape-in-cursor-position-when-user-clicks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!