0

I am working on a PowerPoint add-in using VSTO.

I want to insert a button into the current slide of a PowerPoint, that when clicked calls a function in my code behind. Something like the following: `

PowerPoint.Slide Sld = Globals.ThisAddIn.Application.ActiveWindow.View.Slide;
            PowerPoint.Shape shape = Sld.Shapes.AddShape(MsoAutoShapeType.msoShapeActionButtonCustom, 0, 100, 500, 50);
            shape.TextFrame.TextRange.InsertAfter("This text was also added by using code.");
            shape.Name = "shape3";
            //when clicked, run method abc()

` i'm struggling to find anyone who has actually made a button inside the PowerPoint slide, that runs some code. What most people do is have a button in the ribbon, and program that one, but that isn't what i'm interested in. I simply can't figure out how to add an eventlistener or something alike to the button inside the slide.

Can anyone help me on this issue?

I've found the Shape.Script.ScriptText, but i can't figure how it actually works, of if it even is a way to fix my problem

            shape.Script.ScriptText = ??somescript??

Neither am i certain that the code above even is the right approach at all. All i know is that it works for inserting textboxes and the like, but they aren't interactive.

Update I've stumpled upon something like

PowePoint.Shape shape = Sld.Shapes.AddOLEObject(0, 100, 500, 50, "Forms.CommandButton.1", "", 
                Office.MsoTriState.msoFalse, "", 0, "", Office.MsoTriState.msoFalse);

Which inserts a nice button into the slide, and i've also found this https://www.youtube.com/watch?v=tnXPgy0BCp4&ab_channel=DigitalCatalog which is a video of how to use this sort of commandbutton in excel, and apply code to it. All i am missing is how to choose which code the CommandButton is running, when clicked, in my addin.

Edit I've given up on the idea, I simply couldn't see how. Instead i have an eventlistener on slidechanges, and prevent the slidechange from happening, which then works as my button. That does mean i can only have one "button" on a slide, but luckily i don't need more for this project.

It does seem possible to do, in a somewhat more complicated way, looking at the coordinates of the mouse, and doing it from scratch. check out following: How to invoke an action during powerpoint slideshow programmatically?

0 Answers0