在C#中嵌入Power Point

时间:2013-02-25 10:35:35

标签: c# powerpoint

我有兴趣在窗口面板中播放Power Point演示文稿。     它在Panel中的播放功率点文件,但问题是,它首先在几秒钟内全屏播放它继续在Panel中播放。     但我需要直接在面板上玩。     如果有人知道,请帮助。

using System.Diagnostics;
using System.Runtime.InteropServices;
using ppt = Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;


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

        ppt.Presentation presentation;
        Microsoft.Office.Interop.PowerPoint.SlideShowView oSlideShowView;
        bool flag = false;

        public void open(string FileName)
        {
            try
            {
                ppt.Application application;

                // For Display in Panel
                IntPtr screenClasshWnd = (IntPtr)0;
                IntPtr x = (IntPtr)0;

                application = new ppt.Application();

                presentation = application.Presentations.Open(FileName, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);



                panel1.Controls.Add(application as Control);
                ppt.SlideShowSettings sst1 = presentation.SlideShowSettings;


                sst1.LoopUntilStopped = Microsoft.Office.Core.MsoTriState.msoCTrue;

                ppt.Slides objSlides = presentation.Slides;



                sst1.LoopUntilStopped = MsoTriState.msoTrue;


                sst1.StartingSlide = 1;
                sst1.EndingSlide = objSlides.Count;



                panel1.Dock = DockStyle.Fill;



                sst1.ShowType = ppt.PpSlideShowType.ppShowTypeKiosk;



                ppt.SlideShowWindow sw = sst1.Run();


                oSlideShowView = presentation.SlideShowWindow.View;




                IntPtr pptptr = (IntPtr)sw.HWND;


                SetParent(pptptr, panel1.Handle);


            }
            catch (Exception)
            {

                throw;
            }


        }
        private void Form3_Load(object sender, EventArgs e)
        {
            string FileName = "D:\\test.pptx";
            open(FileName);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            oSlideShowView.Next();
        }

0 个答案:

没有答案