0
我正在爲自定義功能區執行添加操作,並且在編寫要由功能區按鈕(回調方法)執行的代碼時,引用屬於Pwp的代碼時出現錯誤API(我在項目的引用中有API,儘管它的「Copy Local」屬性是False,我不能使它成爲True(不知道這是否是一個問題))。如何使用Pwp對象? (無法獲取形狀的寬度和高度)
因此,我不能做任何事......
代碼:
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#在這種情況下,我怎麼能工作????