我想做的是从我的WPF应用程序控制Powerpoint演示文稿。使用此问题中的代码:C# - way to programmatically advance Powerpoint slide show?,它对于常规幻灯片效果运作良好。
但是,一旦到达一个由鼠标单击触发的动画幻灯片,它就无法按照我期望的方式工作。当进入这样的幻灯片时,它会按预期显示,但是当我调用objPres.SlideShowWindow.View.Next()时,它什么也不做,而在第二或第三次点击后,它直接转到下一张幻灯片,没有动画效果。
奇怪的是: 当我通过计时器调用objPres.SlideShowWindow.View.Next()时,它可以正常工作!动画按预期运行。
这是我所拥有的代码:
但是,一旦到达一个由鼠标单击触发的动画幻灯片,它就无法按照我期望的方式工作。当进入这样的幻灯片时,它会按预期显示,但是当我调用objPres.SlideShowWindow.View.Next()时,它什么也不做,而在第二或第三次点击后,它直接转到下一张幻灯片,没有动画效果。
奇怪的是: 当我通过计时器调用objPres.SlideShowWindow.View.Next()时,它可以正常工作!动画按预期运行。
这是我所拥有的代码:
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();
}
我相信这是一件很简单的事情,但我可能忽略了什么。我已经为此苦恼了很长时间 :(