2

Anyone know how to make one or how to download a control to view powerpoint documents?

I've searched, but the only thing that comes up is this, which is decidedly not free. I'm sure Microsoft must have a control that does this already.

Make one control to do that it also welcome.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
diogopalhais
  • 369
  • 1
  • 4
  • 14
  • this was discussed many times, best approach seems to be using the web browser control to show the ppt file, see previous questions eg: http://stackoverflow.com/questions/1259369/embed-powerpoint-viewer-in-c-sharp-win-form – Davide Piras Mar 08 '12 at 17:11

2 Answers2

4

Here have the solution to the problem i have looking after. If anyone has the same problem i leave here the solution made by me after many hours of work.

        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        static extern IntPtr FindWindow(IntPtr ZeroOnly, string lpWindowName);

        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern bool SetWindowText(IntPtr hwnd, String lpString);


        private string FileName = "";
        PowerPoint.Application application;
        PowerPoint.Presentation presentation;
        bool flag = false;

        public UserControl1()
        {
            InitializeComponent();
        }


        public void open()
        {
            sair();

            openFileDialog1.Filter = "Powerpoint file (*.ppt)|*.ppt|All files (*.*)|*.*";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FileName = openFileDialog1.FileName;

                IntPtr screenClasshWnd = (IntPtr)0;
                IntPtr x = (IntPtr)0;

                flag = true;

                application = new PowerPoint.Application();
                presentation = application.Presentations.Open2007(FileName, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue);
                PowerPoint.SlideShowSettings sst1 = presentation.SlideShowSettings;


                sst1.ShowType = (PowerPoint.PpSlideShowType)1;
                PowerPoint.SlideShowWindow sw = sst1.Run();


                sw.Height = (panel1.Height) - 64;
                sw.Width = (panel1.Width) - 130;

                IntPtr formhWnd = FindWindow(x, "Form1");
                IntPtr pptptr = (IntPtr)sw.HWND;
                screenClasshWnd = FindWindow(x, "screenClass");
                SetParent(pptptr, panel1.Handle);

                this.Focus();

                this.application.SlideShowEnd += new Microsoft.Office.Interop.PowerPoint.EApplication_SlideShowEndEventHandler(SlideShowEnds);
            }
        }
diogopalhais
  • 369
  • 1
  • 4
  • 14
  • Hi, this looks really interesting @NickHalden, but I cannot see where some things are defined, for example the sair() method? – KingCronus Jul 08 '12 at 10:29
2

The easiest way to do it is to use the PowerPoint Interop namespace. You can read about it on the MSDN site. One caveat, is that it requires that you have PowerPoint installed. So, if this is going to be for commercial software, it would be moot since the customer would have to buy PowerPoint anyways. But for many tasks, it is nifty and with .NET 4.0 makes working with MS Office easy.

Jetti
  • 2,418
  • 1
  • 17
  • 25
  • I already use PowerPoint Interop but its not what i want. I want to embedded into a c# form a window with the ppt viewer and the only way to do this is create or use a ppt viewer as a control. The PowerPoint Interop create a instance of PowerPoint and uses the full screen to display. – diogopalhais Mar 08 '12 at 18:03
  • @NickHalden then I would suggest taking a look at what Davide Piras linked to in the comments – Jetti Mar 08 '12 at 18:40