如何从鼠标的屏幕位置推导出一个形状的幻灯片ppt位置 [英] how to deduce the slide ppt position of a shape from the screen position of the mouse
问题描述
我正在使用 VB 为 Powerpoint 实现自定义任务窗格.我想在鼠标位置的活动幻灯片上显示图像形状.我通过使用System.windows.froms.control.MousePosition.Y"知道鼠标的屏幕位置..所以现在将其转换为幻灯片ppt位置并填充属性shape.top"会很棒.
I'm using VB to implement a custom task pane for Powerpoint. I would like to display an image shape on the active powerpoint slide at the position of the mouse. I know screen position of the mouse by using " System.windows.froms.control.MousePosition.Y " .. So now it would be great to transform it into slide ppt position and fill the property "shape.top".
我尝试了screentoclient"功能,但它不起作用.ppt幻灯片上shape.top的单位是什么?鼠标的屏幕坐标单位是什么?
I tried the function "screentoclient" but it doesn't work. What is the unit of shape.top on ppt slide? what is the unit of mouse's screen coordinates?
重要的是该解决方案适用于任何尺寸的屏幕......
It is important that the solution works for any size of the screen ...
推荐答案
试试这个(VBA ...你需要转换为 .NET)
Have a go with this (VBA ... you'll need to translate to .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
这篇关于如何从鼠标的屏幕位置推导出一个形状的幻灯片ppt位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!