Powerpoint Viewer control C# / VB / .NET

本秂侑毒 提交于 2019-12-18 12:42:13

问题


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.


回答1:


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);
            }
        }



回答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.



来源:https://stackoverflow.com/questions/9621771/powerpoint-viewer-control-c-sharp-vb-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!