做了一个倒计时的小软件,用于PPT倒计时。如何捕获ppt的播放,然后倒计时开始;
ppt退出播放后,倒计时结束。怎么捕获它的事件:ShowSlideBegin   和   ShowSlideEnd  看了一下
https://support.microsoft.com/zh-tw/help/308825/how-to-handle-powerpoint-events-with-visual-c-.net也没弄懂。到底如何来捕获呢?

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using PowerPoint = Microsoft.Office.Interop.PowerPoint;namespace PPTEventTest
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private PowerPoint.Application oPPT;        private void button1_Click(object sender, EventArgs e)
            {
                oPPT = new PowerPoint.Application();
                oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
                oPPT.Activate();            oPPT.SlideShowBegin += new PowerPoint.EApplication_SlideShowBeginEventHandler(SlideShowBegin);
                oPPT.SlideShowEnd += new PowerPoint.EApplication_SlideShowEndEventHandler(SlideShowEnd);        }        private void SlideShowEnd(PowerPoint.Presentation Pres)
            {
                this.listBox1.Items.Add("结束放映");
            }        private void SlideShowBegin(PowerPoint.SlideShowWindow Wn)
            {
                this.listBox1.Items.Add("开始放映");
            }        private void Form1_Load(object sender, EventArgs e)
            {
                System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
            }        private void button2_Click(object sender, EventArgs e)
            {            oPPT.SlideShowBegin -= SlideShowBegin;
                oPPT.SlideShowEnd -= SlideShowEnd;
                oPPT.ActivePresentation.Saved = Microsoft.Office.Core.MsoTriState.msoTrue;
                oPPT.ActivePresentation.Close();            oPPT.Quit();
                oPPT = null;
                //GC.Collect();
            }    }
    }
      

  2.   


    多谢!
    PowerPoint = Microsoft.Office.Interop.PowerPoint; 改成了PPt = Microsoft.Office.Interop.PowerPoint;后面的也都替换成了PPt
    我把 按钮1 点击事件里面的代码放在了 Form1_Load中,去掉了
    oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
                oPPT.Activate();
    不想一运行就出来ppt
    按钮2 里的代码也用不到。  我运行此程序,然后手动打开ppt,一开始播放ppt的话,就想着能倒计时。
    但是,我的倒计时代码z_time.Start();放在private void SlideShowBegin(PPt.SlideShowWindow Wn)
            {}里面,就是不倒计时啊。这是为什么呢?
      

  3.   

    ppt获得播放状态后,就是不能倒计时啊?是不是timer和ppt有关的东西,有冲突呢?还有其他的方法能获取到ppt的播放和结束吗?
      

  4.   

    加了一个计时器w1,获取放映总时间,定时器t1进行计数,后者的触发次数放在TimeCount中。        private PowerPoint.Application oPPT;
            private int TimeCount; //t1定时器触发次数
            private System.Timers.Timer t1 = new System.Timers.Timer(1000); //t1定时器,定时间隔1000ms
            private Stopwatch w1 = new Stopwatch();  //w1计时器        private void button1_Click(object sender, EventArgs e)
            {            oPPT = new PowerPoint.Application();
                oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
                oPPT.Activate();            oPPT.SlideShowBegin += new PowerPoint.EApplication_SlideShowBeginEventHandler(SlideShowBegin);
                oPPT.SlideShowEnd += new PowerPoint.EApplication_SlideShowEndEventHandler(SlideShowEnd);            t1.Elapsed += new System.Timers.ElapsedEventHandler(TimerElapsed1);        }        private void TimerElapsed1(object sender, System.Timers.ElapsedEventArgs e)
            {
                TimeCount++;
                //listBox1.Items.Add("t1已触发次数:" + TimeCount);
            }        private void SlideShowEnd(PowerPoint.Presentation Pres)
            {
                this.listBox1.Items.Add("结束放映");
                t1.Stop();
                w1.Stop();
                listBox1.Items.Add("t1触发次数:"+TimeCount );
                listBox1.Items.Add("w1计时:"+ w1.Elapsed );
                listBox1.Items.Add("t1和w1停止");
                w1.Reset(); //计时器归零
            }        private void SlideShowBegin(PowerPoint.SlideShowWindow Wn)
            {
                this.listBox1.Items.Add("开始放映");
                TimeCount = 0;
                t1.AutoReset = true;
                t1.Start();
                w1.Start();            listBox1.Items.Add("t1和w1启动");
            }
      

  5.   

    对于WPS的幻灯片似乎无效!