|
楼主 |
发表于 2014-6-5 14:36
|
显示全部楼层
我已写代码实现了此功能,还是要感谢楼上的各位给出的回复!
主要思路是先获得鼠标在屏幕坐标下的位置信息,在通过自己的转化,将位置信息从屏幕坐标系转到页面坐标下,转化代码如下:
'得到鼠标的屏幕坐标
Dim sx As Long
Dim sy As Long
sx = getmouse_x_y.X
sy = getmouse_x_y.Y
Dim pLeft As Long
Dim pTop As Long
Dim pWidth As Long
Dim pHeight As Long
'得到屏幕坐标系下页面左顶点和右顶点的位置
Dim shapestar As Word.shape
Set shapestar = ActiveDocument.Shapes.AddShape(msoShape5pointStar, _
0, 0, 0, 0)
ActiveDocument.ActiveWindow.GetPoint pLeft, pTop, _
pWidth, pHeight, shapestar
shapestar.Delete
'得到当前页面放大比率
Dim sZoom As Single
sZoom = ActiveDocument.ActiveWindow.View.Zoom.Percentage / 100
'转化鼠标位置,从屏幕坐标系转到页面坐标系
Dim pleftdis As Long
Dim ptopdis As Long
Dim ptextboxleft As Long
Dim ptextboxtop As Long
ptextboxleft = 0
ptextboxtop = 0
pleftdis = sx - pLeft
ptopdis = sy - pTop
If pleftdis > 0 Then
ptextboxleft = pleftdis / 1.333 / sZoom
End If
If ptopdis > 0 Then
ptextboxtop = ptopdis / 1.333 / sZoom
End If
'ptextboxleft、ptextboxtop为得到的相应页面坐标
'在页面相应位置插入文本框 |
|