我正在开发一个项目,我需要在Windows窗体中嵌入一个PowerPoint查看器。我正在使用以下activeX控件:http://www.daolnwod.com/free-powerpoint-viewer-activex.html。
我激活了控件以与表单设计器的工具箱一起使用并将其拖到我的表单中。然后我将InitializeComponent()方法中的代码编辑为以下内容:
this.axPowerPointViewer1 = new AxPOWERPOINTVIEWERLib.AxPowerPointViewer();
((System.ComponentModel.ISupportInitialize)(this.axPowerPointViewer1)).BeginInit();
this.axPowerPointViewer1.Enabled = true;
this.axPowerPointViewer1.Location = new System.Drawing.Point(0, 0);
this.axPowerPointViewer1.Name = "axPowerPointViewer1";
this.axPowerPointViewer1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axPowerPointViewer1.OcxState")));
this.axPowerPointViewer1.Size = new System.Drawing.Size(925, 573);
this.axPowerPointViewer1.TabIndex = 5;
//this.axPowerPointViewer1.CreateControl();
this.Controls.Add(this.axPowerPointViewer1);
((System.ComponentModel.ISupportInitialize)(this.axPowerPointViewer1)).EndInit();
在我的Forms构造函数
中public Form1()
{
InitializeComponent();
axPowerPointViewer1.Show();
bool loaded = axPowerPointViewer1.LoadFile(@"C:\Debug\test2.ppt"); // loaded = false
string z = axPowerPointViewer1.GetSlideCount().ToString();
}
但是,当我打开表单时,没有任何显示。代码编译但我看不到我一直在研究的测试幻灯片。我为'Previous'和'Next'幻灯片创建了2个按钮,但调试每次都给我一个0的幻灯片位置,所以一定是错的,我似乎无法找到它。
<小时/> 的更新
问题已经解决了。好像我没有调用axPowerPointviewer1.InitControl()。它仍然有一些麻烦,有时它不会在启动时显示第一张幻灯片。如果事情继续顺利进行,我会发布这个问题的答案。
答案 0 :(得分:2)
问题在于初始化控件。为了使控件完全正常运行,您需要调用InitControl()方法,因此调用以下代码调用应该使程序工作:
private void Form1_Load(object sender, EventArgs e)
{
this.axPowerPointViewer1.InitControl();
}