如何从鼠标的屏幕位置推导出形状的滑动ppt位置

时间:2013-12-26 13:50:35

标签: vb.net vba vsto powerpoint

我正在使用VB为Powerpoint实现自定义任务窗格。 我想在鼠标位置的活动powerpoint幻灯片上显示图像形状。 我通过使用“System.windows.froms.control.MousePosition.Y”来了解鼠标的屏幕位置。所以现在将它转换为幻灯片ppt位置并填充属性“shape.top”会很棒。

我尝试了“screentoclient”功能,但它不起作用。 ppt幻灯片上shape.top的单位是什么?鼠标屏幕坐标的单位是多少?

解决方案适用于任何尺寸的屏幕都很重要......

1 个答案:

答案 0 :(得分:2)

顺便说一句(VBA ......你需要翻译成.NET)

Sub Test()

    Dim oSh1 As Shape
    Dim oSh2 As Shape

    ' Assuming nothing on the slide but two rectangles
    ' The first with its left edge just touching the left of the slide
    ' The second with its RIGHT edge just touching the right of the slide:

    Set oSh1 = ActivePresentation.Slides(1).Shapes(1)
    Set oSh2 = ActivePresentation.Slides(1).Shapes(2)

    MsgBox "Upperleft = " & vbCrLf _
        & oSh1.Left & " / " & ActivePresentation.Windows(1).PointsToScreenPixelsX(oSh1.Left) & vbCrLf _
        & oSh2.Left + oSh2.Width & " / " & ActivePresentation.Windows(1).PointsToScreenPixelsX(oSh2.Left + oSh2.Width)

    ' Or just working directly with the slide dimensions:
    MsgBox "Upperleft = " & vbCrLf _
        & 0 & " / " & ActivePresentation.Windows(1).PointsToScreenPixelsX(0) & vbCrLf _
        & ActivePresentation.PageSetup.SlideWidth & " / " & ActivePresentation.Windows(1).PointsToScreenPixelsX(ActivePresentation.PageSetup.SlideWidth)

    ' Both give exactly the same results

End Sub