Paste a picture from clipboard to slide - how? (C#)

Add-in Express™ Support Service
That's what is more important than anything else

Paste a picture from clipboard to slide - how? (C#)
I'm trying to past a jpeg directly onto the current slide using C# 
D E




Posts: 59
Joined: 2009-06-19
How can one paste an image file (be it .jpg .bmp or similar) from the clipboard (where I have already saved it from a pre-existing file) directly onto a .ppt slide. NOTE: If it is possible to paste it directly from a file on the file system that would be just as good a solution (putting it on the clipboard first was just a workaround).

Workflow:
I have added a button and a ribbon to the menu structure, and when I click 'insert' (my new button) one can choose a picture from a password-protected web-based media database belonging to the Powerpoint user. On choosing a photo, it gets copied to the clipboard - the last step should be that it is added to the current slide (how would one point at that programatically anyway?) I don't know how to do the paste.

I would be very grateful for a solution, as I have googled for a day or more without finding out anything of any use. I'm programming in C#.

Thank you very much in advance. D.
Posted 29 Jun, 2009 04:22:16 Top
Andrei Smolin


Add-in Express team


Posts: 19213
Joined: 2006-05-11
Hello D,

Try using the AddPicture method of the Shapes interface. Say, the following VBA code works fine for me:

ActivePresentation.Slides(1).Shapes.AddPicture("D:\Temp Files\untitled.bmp", msoTrue, msoTrue, 0, 0)


Also see http://www.add-in-express.com/docs/net-office-tips.php#getting-help.


Andrei Smolin
Add-in Express Team Leader
Posted 29 Jun, 2009 09:47:16 Top
D E




Posts: 59
Joined: 2009-06-19
Thanks Andrei

You use 'ActivePresentation' - where does this come from? When I use the snippet you provide, I get "the name ActivePresentation does not exist in the current context". I tried qualifiying it with:
PowerPoint.Application.ActivePresentation.Slides(1)....
But then I get "An object reference is required for the non-static...PowerPoint.Application.ActivePresentation.get"

I don't know where the 'get' bit comes from - my(well, your) code doesn't mention 'get'.

I would also be really pleased to hear what the args: msoTrue, msoTrue, 0, 0 all do.

..And finally, how do I determine the CURRENT SLIDE, i.e. which number slide currently has the focus. Any offers?

Thanks again for all help offered.
D.

OH and by the way - if anyone could give me the code in C# I'd be a happy bunny...or is it not possible in C#?
Posted 30 Jun, 2009 04:51:25 Top
Andrei Smolin


Add-in Express team


Posts: 19213
Joined: 2006-05-11
Sure, it's possible.

Try using the following in your add-in module, say in a button click:

PowerPointApp.ActivePresentation.Slides.Item(1).Shapes.AddPicture("D:\Temp Files\untitled.bmp", Office.MsoTriState.msoTrue, Office.MsoTriState.msoTrue, 0, 0, Type.Missing, Type.Missing);



Andrei Smolin
Add-in Express Team Leader
Posted 30 Jun, 2009 12:08:11 Top
Andrei Smolin


Add-in Express team


Posts: 19213
Joined: 2006-05-11

Mmm, I was too quick. Sorry. Here is the code that works fine for me:

private void adxRibbonButton1_OnClick(object sender, AddinExpress.MSO.IRibbonControl control, bool pressed)
{
    float left = 0;
    float top = 0;
    PowerPointApp.ActivePresentation.Slides.Item(1).Shapes.AddPicture(@"D:Temp Filesuntitled.bmp", Office.MsoTriState.msoTrue, Office.MsoTriState.msoTrue, left, top, -1, -1);
}



Andrei Smolin
Add-in Express Team Leader
Posted 30 Jun, 2009 12:16:15 Top