gpt4 book ai didi

c# - 使用点击动画以编程方式推进 Powerpoint 幻灯片放映

转载 作者:太空狗 更新时间:2023-10-29 21:46:32 26 4
gpt4 key购买 nike

我想做的是从我的 WPF 应用程序控制 Powerpoint 演示文稿。使用此问题的代码: C# - way to programmatically advance Powerpoint slide show?它适用于普通幻灯片。

但是当我看到一张带有鼠标点击触发的动画的幻灯片时,它并没有像我期望的那样工作。当转到这样的幻灯片时,它会按预期显示,但是当我调用 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();
}

我确信这很容易,但我忽略了一些事情。但是我已经为此苦苦思索了很长一段时间:(

最佳答案

我在 MSDN 论坛上找到了问题的解决方案:使用按钮时,由于PPT没有焦点,动画无法正常播放。当我在调用 oSlideShowView.Next() 之前激活 SlideShowWindows 时,它起作用了:

private void OnNextClicked(object sender, RoutedEventArgs e)
{
oSlideShowView.Application.SlideShowWindows[1].Activate();
oSlideShowView.Next();
}

关于c# - 使用点击动画以编程方式推进 Powerpoint 幻灯片放映,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8402839/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com