none
Help regarding power point presentation opening in winforms c# RRS feed

  • General discussion

  • Hi, i opened power point presentation in window forms. but i want to attach scroll-er or any other component which open the next slide of presentation file. how could i do this?

    here is the code for opening presentation file in window forms

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Office.Core;
    using Application = Microsoft.Office.Interop.PowerPoint.Application;
    using Microsoft.Office.Interop.PowerPoint;
    using System.Runtime.InteropServices;
    
    namespace PPTViewer
    {
        public partial class Form1 : Form
        {
    
            [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            static extern IntPtr FindWindow(string className, string windowtext);
    
            [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
            }
    
    
            public void powerpointviewer()
            {
                OpenFileDialog obj = new OpenFileDialog();
                obj.ShowDialog();
                string filename = obj.FileName;
    
                Application objApp = new Application();
                //objApp.Visible = MsoTriState.msoTrue;
                Presentations objPresSet = objApp.Presentations;
                Presentation objPres = objPresSet.Open(filename, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
                Slides objSlides = objPres.Slides;
    
                //Run the Slide show
                SlideShowSettings objSSS = objPres.SlideShowSettings;
                objSSS.ShowType = Microsoft.Office.Interop.PowerPoint.PpSlideShowType.ppShowTypeSpeaker;
                objSSS.LoopUntilStopped = MsoTriState.msoTrue;
                objSSS.Run();
    
                WindowWrapper handleWrapper = new WindowWrapper((IntPtr)objPres.SlideShowWindow.HWND);
                SetParent(handleWrapper.Handle, this.panel1.Handle);
                this.panel1.Visible = true;
                objPres.SlideShowWindow.Height = this.panel1.Height;
                objPres.SlideShowWindow.Width = panel1.Width;
                objPres.SlideShowWindow.Top = 0;
                objPres.SlideShowWindow.Left = 0;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                powerpointviewer();
    
            }
    
            }//end powerpointviwer
    
        class WindowWrapper : System.Windows.Forms.IWin32Window
        {
            private IntPtr _hwnd;
            public WindowWrapper(IntPtr handle)
            {
                _hwnd = handle;
            }
    
            public IntPtr Handle
            {
                get
                {
                    return _hwnd;
                }
            }
        }
    
    }
    



    !~~~Prince~~~!

    • Moved by CoolDadTx Friday, February 6, 2015 3:04 PM Office related
    Friday, February 6, 2015 1:30 PM

All replies

  • Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
                ppApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
                Microsoft.Office.Interop.PowerPoint.Presentations oPresSet = ppApp.Presentations;
                Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(@"D:\Office\temp.pptx", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse,
                Microsoft.Office.Core.MsoTriState.msoTrue);


    Mark as answer or vote as helpful if you find it useful | Ammar Zaied [MCP]

    Friday, February 6, 2015 1:33 PM
  • Hello Taimoor,

    It looks like you are interested in the ShowScrollbar property of the SlideShowSettings class.

    Also the Slide class provides the Select method. If you try to make a selection that isn't appropriate for the view, your code will fail. For example, you can select a slide in slide sorter view but not in slide view.

    Friday, February 6, 2015 3:22 PM
  • Hello again,

    i used these properties to handle slides view

    SlideShowWindow.View.Previous();
    SlideShowWindow.View.Next();
    but i have a problem. open slide in panel. i want to fit the slide in panel but failed to fit. how to i fit whole slide in this panel

    !~~~Prince~~~!

    Saturday, February 7, 2015 9:07 PM