是否可以将PowerPoint Viewer嵌入到C#Windows窗体中?
我目前使用以下代码:
objApp = new PowerPoint.Application();
//objApp.Visible = MsoTriState.msoTrue;
objPresSet = objApp.Presentations;
objPres = objPresSet.Open(ppsAction.FileInfo.FullName, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
objSlides = objPres.Slides;
//Run the Slide show
objSSS = objPres.SlideShowSettings;
objSSS.ShowType = Microsoft.Office.Interop.PowerPoint.PpSlideShowType.ppShowTypeSpeaker;
objSSS.LoopUntilStopped = MsoTriState.msoTrue;
objSSS.Run();
WindowWrapper handleWrapper = new WindowWrapper(objPres.SlideShowWindow.HWND);
SetParent(handleWrapper.Handle, this.ApplicationPanel.Handle);
this.ApplicationPanel.Visible = true;
objPres.SlideShowWindow.Height = ApplicationPanel.Height;
objPres.SlideShowWindow.Width = ApplicationPanel.Width;
objPres.SlideShowWindow.Top = 0;
objPres.SlideShowWindow.Left = 0;
Run Code Online (Sandbox Code Playgroud)
它在表单上显示查看器,但放置和大小调整是错误的.如何正确放置和放置它.
另一种选择:
我遇到过Aximp.exe应用程序,用于在C#中显示Win窗体上的ActiveX控件.我如何在PPT Viewer中使用它?
我这样做了吗?
我得到一个指向本机数组的指针,需要复制到托管数组.将memcpy()与pin_ptr一起使用.
unsigned char* pArray;
unsigned int arrayCount;
// get pArray & arrayCount (from a COM method)
ManagedClass->ByteArray = gcnew array<Byte,1>(arrayCount)
pin_ptr<System::Byte> pinPtrArray = &ManagedClass->ByteArray[0];
memcpy_s(pinPtrArray, arrayCount, pArray, arrayCount);
Run Code Online (Sandbox Code Playgroud)
arrayCount是pArray的实际长度,因此并不担心这个方面.查看代码并从向量中复制数组.所以我可以安全地设置托管数组大小.
在设置 out 参数的值之前引发异常,然后尝试访问该参数时,C# 中定义的行为是什么?
public void DoSomething(int id, out control)
{
try
{
int results = Call(Id);
control = new CallControl(results);
}
catch(Exception e)
{
throw new Exception("Call failed", e);
}
}
//somewhere else
DoSomething(out Control control)
{
try
{
DoSomething(1, out control);
}
catch()
{
// handle exception
}
}
// later
Control control;
DoSomething(out control)
control.Show();
Run Code Online (Sandbox Code Playgroud)
编译器通常会抱怨在设置 out 参数之前退出该方法。这似乎比它更聪明,无法保护我免受自己的伤害。