问题描述
全部,
我正在创建一个带有按钮的自定义功能区选项卡的Powerpoint加载项。
I am creating a Powerpoint add-in that has a custom ribbon tab with a button.
单击按钮时,我想在活动幻灯片上添加一个形状(例如,文本框)。
On button click, i want to add a shape (e.g., textbox) on the active slide.
我遇到的挑战是我不知道如何从中引用Slide对象自定义功能区类
Challenge I am running into is that I do not know how to refer to Slide object from the custom ribbon class
Imports Microsoft.Office.Tools.Ribbon
Public Class Ribbon1
Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button1.Click
''''''How do i reference active slide in this event???
End Sub
End Class
我已经在Powerpoint VBA中编程了很多,但是很新的使用Visual Studio创建VSTO插件。
I have programmed a lot in Powerpoint VBA, but new to using Visual studio to create VSTO plugin.
非常感谢任何帮助!
N
推荐答案
它类似于VBA,但你需要首先获得Application对象,然后你可以通过ActiveWindow.View.Slide引用活动的幻灯片对象。
It's similar with VBA, but you need to get Application object at first and then you could refer to active slide object via ActiveWindow.View.Slide .
这是一个例子。
Imports PPT = Microsoft.Office.Interop.PowerPoint
Dim app As PPT.Application = Globals.ThisAddIn.Application
Dim pre As PPT.Presentation = app.ActivePresentation
Dim sli As PPT.Slide = app.ActiveWindow.View.Slide
Dim shp As PPT.Shape = sli.Shapes.AddShape(Type:=Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, _
Left:=150, Top:=150, Width:=50, Height:=50)
shp.Fill.ForeColor.RGB = RGB(100, 100, 100)
问候,
Celeste
这篇关于自定义功能区按钮将文本框添加到演示文稿中的活动幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!