通过点击动画以编程方式推进Powerpoint幻灯片
本文关键字:方式推 Powerpoint 幻灯片 编程 动画 | 更新日期: 2023-09-27 18:16:52
我想做的是从我的WPF应用程序控制Powerpoint演示文稿。用这个问题的代码:c# -如何以编程方式推进Powerpoint幻灯片展示?它在普通幻灯片上工作得很好。
但是,只要我得到一个由鼠标点击触发动画的幻灯片,它就不会像我期望的那样工作。当去到这样的幻灯片时,它会像预期的那样显示,但是当我调用objpress . slideshowwindow . view . next()时,它什么也不做,在第二次或第三次点击之后,它直接去到下一张幻灯片,没有动画。
奇怪的是:当我通过计时器调用objpress . 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();
}
我相信这是很容易的,我忽略了一些东西。但是我已经纠结了很长一段时间了
我在MSDN论坛上得到了我的问题的解决方案:使用按钮时,由于PPT没有焦点,动画无法正常播放。当我在调用oSlideShowView.Next()之前激活SlideShowWindows时,它可以工作:
private void OnNextClicked(object sender, RoutedEventArgs e)
{
oSlideShowView.Application.SlideShowWindows[1].Activate();
oSlideShowView.Next();
}