What I'm trying to do is control the Powerpoint presentation from my WPF application. With the code from this question: C # - way to programmatically promote a Powerpoint slideshow? It works well enough for regular slides.
But as soon as I get to the slide with the animation caused by mouseclick, it does not work, as I would expect it. When you go to such a slide, it will be displayed as expected, but when I call objPres.SlideShowWindow.View.Next (), it does nothing, and after the second or third click it goes directly to the next slide, without animation.
The strange thing: When I call objPres.SlideShowWindow.View.Next () via a timer, it works! Animation works as expected.
This is the code I have:
Microsoft.Office.Interop.PowerPoint.Application oPPT; Microsoft.Office.Interop.PowerPoint.Presentations objPresSet; Microsoft.Office.Interop.PowerPoint.Presentation objPres; Microsoft.Office.Interop.PowerPoint.SlideShowView oSlideShowView; Timer slidetest; private void OpenPPT(object sender, RoutedEventArgs e) { //Create an instance of PowerPoint. oPPT = new Microsoft.Office.Interop.PowerPoint.Application(); // Show PowerPoint to the user. oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; objPresSet = oPPT.Presentations; OpenFileDialog Opendlg = new OpenFileDialog(); Opendlg.Filter = "Powerpoint|*.ppt;*.pptx|All files|*.*"; // Open file when user click "Open" button if (Opendlg.ShowDialog() == true) { string pptFilePath = Opendlg.FileName; //open the presentation objPres = objPresSet.Open(pptFilePath, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue); objPres.SlideShowSettings.ShowPresenterView = MsoTriState.msoFalse; System.Diagnostics.Debug.WriteLine(objPres.SlideShowSettings.ShowWithAnimation); objPres.SlideShowSettings.Run(); oSlideShowView = objPres.SlideShowWindow.View; slidetest = new Timer(4000); slidetest.AutoReset = false; slidetest.Elapsed += new ElapsedEventHandler(slidetest_Elapsed); slidetest.Start(); } } void slidetest_Elapsed(object sender, ElapsedEventArgs e) { // this works as expected oSlideShowView.Next(); } private void OnNextClicked(object sender, RoutedEventArgs e) { // this doesn't work, animations aren't shown at all. oSlideShowView.Next(); }
I am sure this is something simple, and I'm missing something. But I have been knocking myself on this for quite some time :(
source share