当前位置: 动力学知识库 > 问答 > 编程问答 >

Visual C# - InvalidActiveXStateException

问题描述:

I am getting an error when trying to embed a flash (.swf) file into my Visual C' form - I have notice this is a fairly common error, though the solutions don't mean much to me.

Here is my code:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using AxShockwaveFlashObjects;

using ShockwaveFlashObjects;

namespace WindowsFormsApplication1

{

public partial class Form6 : Form

{

public Form6()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

Form1 frm1 = new Form1();

frm1.ShowDialog();

}

private void axShockwaveFlash2_Enter(object sender, EventArgs e)

{

**//this.axShockwaveFlash1.LoadMovie(0, "C:\\Documents and Settings\\Gary\\My Documents\\Flash File\\CalmBay1.swf");**

}

private void Form6_Load(object sender, EventArgs e)

{

AxShockwaveFlash axShockwaveFlash = new AxShockwaveFlash();

axShockwaveFlash.Location = new System.Drawing.Point(50, 50);

this.Controls.Add(axShockwaveFlash);

**axShockwaveFlash.Movie = ("C:\\Documents and Settings\\Gary\\My Documents\\Flash File\\CalmBay1.swf");**

//ShockwaveFlash.Size = new System.Drawing.Size(150, 150);// set size as required

axShockwaveFlash.Play();

}

}

}

The line with the asterix is where the error is, but as i say, i've no idea on how to resolve it!

网友答案:

Even though it's been months since this question was asked, I just had the same problem. When creating AxShockwaveFlash objects programmatically, you have to initialize:

var flashObj = new AxShockwaveFlash();
((ISupportInitialize) (flashObj)).BeginInit(); // <--
flashObj.Dock = DockStyle.Fill;
flashObj.Enabled = true;
((ISupportInitialize) (flashObj)).EndInit(); // <--

Controls.Add(flashObj);

flashObj.AutoSize = true; // All of these properties won't work unless the component has been initialized
flashObj.ScaleMode = 1;
flashObj.AlignMode = 0;
flashObj.LoadMovie(0, @"movie.swf");
flashObj.Stop();
flashObj.Play();

Hopefully this will save future readers some time.

网友答案:

I had the same problem I tried the proposed solutions of calling CreateControl without any success.

It turned out that the interops were generated targeting the .net 2.0 framework and the problem occurred when being called from 4.0 code. The solution was to generate interops using .NET Framework Tools 4.0.

分享给朋友:
您可能感兴趣的文章:
随机阅读: