Mr_Fulano
asked on
Capturing the "SlideShowNextSlide" Event in a PowerPoint Presentation via C#
Hi, I'm using Visual Studio 2010 C#. -- I have the code shown below, which opens a PowerPoint file and places the slides in "presentation" mode. -- That part works.
My Form is nothing but a basic Windows Form with a button on it called the default "button1" name.
You will also need to add the Microsoft.Office.Interop.P owerPoint reference in your Solution Explorer.
The problem I'm having is capturing a change of slide event, which is called ("SlideShowNextSlide"). To test this, I am simply writing a simple message to the console with Console.WriteLine. -- This is the part that does not work.
Basically, what I would like to do is to capture one of the events below:
- a mouse click on the presentation slide, which advances the position to the next slide.
- a key-down event, which advances the position to the next slide.
- a wireless clicker that issues a "next slide" signal, which advances the position to the next slide.
- any "next slide" event.
I think my problem is that I'm not coding the SlideShowNextSlide EventHandler properly, which is based on the documentation I've reviewed regarding this matter.
Fulano
My Form is nothing but a basic Windows Form with a button on it called the default "button1" name.
You will also need to add the Microsoft.Office.Interop.P
The problem I'm having is capturing a change of slide event, which is called ("SlideShowNextSlide"). To test this, I am simply writing a simple message to the console with Console.WriteLine. -- This is the part that does not work.
Basically, what I would like to do is to capture one of the events below:
- a mouse click on the presentation slide, which advances the position to the next slide.
- a key-down event, which advances the position to the next slide.
- a wireless clicker that issues a "next slide" signal, which advances the position to the next slide.
- any "next slide" event.
I think my problem is that I'm not coding the SlideShowNextSlide EventHandler properly, which is based on the documentation I've reviewed regarding this matter.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.Office.Interop;
using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
namespace ppAPPContoller
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string fileToOpen = "";
Stopwatch stopwatch = new Stopwatch();
OpenFileDialog ofd = new OpenFileDialog();
Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
Microsoft.Office.Interop.PowerPoint.SlideShowWindows objSSWs;
Microsoft.Office.Interop.PowerPoint.SlideShowSettings objSSS;
Microsoft.Office.Interop.PowerPoint.SlideShowView oSlideShowView;
private void button1_Click(object sender, EventArgs e)
{
ofd.Filter = "Powerpoint|*.ppt;*.pptx";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
fileToOpen = ofd.FileName;
var pres = ppApp.Presentations;
var file = pres.Open(fileToOpen, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue);
var objSlides = file.Slides;
//Run the Slide Show
objSSS = file.SlideShowSettings;
objSSS.Run();
objSSWs = ppApp.SlideShowWindows;
button1.Enabled = false;
Console.WriteLine("Opening in Presentation mode: " + ofd.SafeFileName);
Console.WriteLine("Full Path: " + ofd.FileName);
}
stopwatch.Start();
}
// Code to capture SlideShowNextSlide Event
private void InitPPT()
{
this.ppApp.SlideShowNextSlide += this.SlideShowNextSlide;
}
private void SlideShowNextSlide(PowerPoint.SlideShowWindow Wn)
{
Console.WriteLine("Slide changed....");
}
private void Form1_FormClosing_1(object sender, FormClosingEventArgs e)
{
ppApp.Quit();
stopwatch.Stop();
}
}
}
Thanks, Fulano
ASKER
Yeah...a lot of the examples I've been reviewing are VBA, but VBA is not my forte. I need to be able to do this in C#. Thanks for your response.
Do you think you can do it in VB? I think VB can be converted to C# with little effort.
Do you think you can do it in VB? I think VB can be converted to C# with little effort.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Daniel, yes indeed...!!! That is the same solution I just came up with. -- WOW, I had been working on this one for almost 2 days! -- Thank you for confirming that I was on track!!! : )
private void MonitorSlideChange()
{
ppApp.SlideShowNextSlide += ppApp_SlideShowNextSlide;
}
private void ppApp_SlideShowNextSlide(S lideShowWi ndow Wn)
{
//Do Stuff....
}
private void MonitorSlideChange()
{
ppApp.SlideShowNextSlide += ppApp_SlideShowNextSlide;
}
private void ppApp_SlideShowNextSlide(S
{
//Do Stuff....
}
ASKER
Great solutions!!!
https://msdn.microsoft.com