【发布时间】:2016-11-12 21:02:32
【问题描述】:
我正在为自定义功能区添加插件,并且在编写要由功能区按钮(回调方法)执行的代码时,在引用属于 Pwp API 的代码时出现错误(我在项目的 API参考文献,虽然它的“Copy Local”属性为 False,我无法将其设为 True(不知道这是否有问题)。
所以我什么都做不了……
代码:
public void SwapPositions(Office.IRibbonControl control, bool isPressed)
{
_Application myPPT = Globals.ThisAddIn.Application;
Slide curSlide = myPPT.ActiveWindow.View.Slide;
curSlide.Shapes.Range(0).Height;
}
在这种情况下,错误出现在最后一条语句中。 VS 说:“只有赋值、调用、递增、递减和新建对象表达式可以作为语句使用”。
如您所见,代码才刚刚开始,因为我无法找到解决方案。 最后,我想在 C# 中复制我在 VBA 中已经拥有的用于切换形状位置的代码:
Sub swap_positions()
Static t1, l1, h1, w1 As Double
Dim t2, l2, h2, w2 As Double
t1 = ActiveWindow.Selection.ShapeRange(1).Top
l1 = ActiveWindow.Selection.ShapeRange(1).Left
h1 = ActiveWindow.Selection.ShapeRange(1).Height
w1 = ActiveWindow.Selection.ShapeRange(1).Width
t2 = ActiveWindow.Selection.ShapeRange(2).Top
l2 = ActiveWindow.Selection.ShapeRange(2).Left
h2 = ActiveWindow.Selection.ShapeRange(2).Height
w2 = ActiveWindow.Selection.ShapeRange(2).Width
'1 Vertical alignment
ActiveWindow.Selection.ShapeRange(1).Top = ActiveWindow.Selection.ShapeRange(2).Top + _
(ActiveWindow.Selection.ShapeRange(2).Height - ActiveWindow.Selection.ShapeRange(1).Height) / 2
'1 Horizontal alignment
ActiveWindow.Selection.ShapeRange(1).Left = ActiveWindow.Selection.ShapeRange(2).Left + _
(ActiveWindow.Selection.ShapeRange(2).Width - ActiveWindow.Selection.ShapeRange(1).Width) / 2
'2 Vertical alignment
ActiveWindow.Selection.ShapeRange(2).Top = t1 + _
(h1 - h2) / 2
'2 Horizontal alignment
ActiveWindow.Selection.ShapeRange(2).Left = l1 + _
(w1 - w2) / 2
End Sub
问题:在这种情况下,我如何在 c# 中处理形状????
【问题讨论】:
标签: c# reference powerpoint add-in shape