PowerPointViewer嵌入问题我在我的主窗体中嵌入了一个PowerPointViewer来显示一个pptx文件。我的计算机上有2个显示器,我正尝试在第二个显示器上运行应用程序。当我在显示器1上运行程序时,一切都按预期工作。但是当我在显示器2上运行它时(意味着我更改代码以在第二台显示器上运行应用程序,而不是运行应用程序然后将其自身移动到第二台显示器),PowerPointViewer将在第一台显示器上打开,然后移动到程序正在运行的第二台显示器。我认为这与未正确设置PowerPoint对象有关,但不太确定。这是我的代码:[DllImport("user32.dll",EntryPoint="FindWindow",SetLastError=true)]staticexternIntPtrFindWindow(IntPtrZeroOnly,stringlpWindowName);[DllImport("user32.dll",SetLastError=true)]staticexternIntPtrSetParent(IntPtrhWndChild,IntPtrhWndNewParent);[DllImport("user32.dll",SetLastError=true,CharSet=CharSet.Auto)]publicstaticexternboolSetWindowText(IntPtrhwnd,StringlpString);[DllImport("user32.dll",CharSet=CharSet.Auto)]publicstaticexternIntPtrSendMessage(IntPtrhWnd,UInt32Msg,IntPtrwParam,UIntPtrlParam);公共结构WM_SETFOCUS=0x0007;Microsoft.Office.Interop.PowerPoint.Application应用程序;Microsoft.Office.Interop.PowerPoint.Presentation演示;publicMainForm(){InitializeComponent();DisplayOnMonitor();}privatevoidMainForm_Load(objectsender,EventArgse){LoadSlideShow();}privatevoidLoadSlideShow(){IntPtrscreenClasshWnd=(IntPtr)0;IntPtrx=(IntPtr)0;申请ication=newMicrosoft.Office.Interop.PowerPoint.Application();演示文稿=application.Presentations.Open2007(Settings.Default.PowerPointPath、Microsoft.Office.Core.MsoTriState.msoTrue、Microsoft.Office.Core.MsoTriState.msoFalse、Microsoft.Office.Core.MsoTriState.msoFalse、Microsoft.Office.Core。MsoTriState.msoFalse);Microsoft.Office.Interop.PowerPoint.SlideShowSettingssst1=presentation.SlideShowSettings;sst1.LoopUntilStopped=Microsoft.Office.Core.MsoTriState.msoTrue;Microsoft.Office.Interop.PowerPoint.SlideShowWindowsw=sst1.Run();IntPtrpptptr=(IntPtr)sw.HWND;SetParent(pptptr,splitContainerControl.Panel1.Handle);splitContainerLeft.Panel1.LostFocus+=newEventHandler(OnLostFocus);splitContainerControl.PreviewKeyDown+=newPreviewKeyDownEventHandler(OnPreviewKeyDown);splitContainerLeft.Panel1.AutoSize=true;splitContainerControl.Panel1.Focus();}privatevoidDisplayOnMonitor(){Screen[]sc;sc=Screen.AllScreens;这.FormBorderStyle=FormBorderStyle.None;this.Left=sc[1].Bounds.Width;this.Top=sc[1].Bounds.Height;this.StartPosition=FormStartPosition.Manual;this.Location=sc[1].边界。位置;Pointp=newPoint(sc[1].Bounds.Location.X,sc[1].Bounds.Location.Y);这个.Location=p;this.WindowState=FormWindowState.Maximized;我知道调用sst1.Run()方法时会出现PowerPoint查看器,但我尝试在之前(和之后)使应用程序不可见,但它会抛出异常如果有一种方法可以指示sst1打开哪个显示,那么我认为它可以解决问题,但到目前为止我还没有运气。任何帮助表示赞赏!以上就是《C#学习教程:PowerPointViewer内嵌问题分享》的全部内容。如果对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
