I need help with InvalidActiveXStateException....

A

ahmadka

Hi guys...well I am trying to create visio control at runtime instead of at
design time....Specifically I have defiined a struct as follows:

struct visioDisplay
{
public AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl
visioControl;
public Visio.Shape[] vNodes;
public Visio.Shape[] vEdges;
public Visio.Page currentPage;
public int visioPageHeight;
public int visioPageWidth;
public int scenarioToBeDrawn;
}

Then I create an array of these structs:

visioDisplay[] visioDisplays;

visioDisplays = new visioDisplay[1];

And finally, I try to access the visioControl in the struct located at first
position in the array:

System.ComponentModel.ComponentResourceManager resources = new
System.ComponentModel.ComponentResourceManager(typeof(MEPMainGUI));
//visioDisplays[0] = new visioDisplay();
visioDisplays[0].visioControl = new
AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl();
visioDisplays[0].visioControl.OcxState =
((System.Windows.Forms.AxHost.State)(resources.GetObject("visio_OcxState")));
visioDisplays[0].visioControl.Window.ShowGuides = 0;

But when the last time executes, I get the
'System.Windows.Forms.AxHost+InvalidActiveXStateException Exception

How can I set this 'state' ? Isnt this the 'ocxstate' that is being set
above ?

Please Help...
 
N

Nikolay Belyh

Hello ahmadka
How can I set this 'state' ?
Isnt this the 'ocxstate' that is being set above ?

This "ocxstate" is generated by form designer to persist control
state,
and it seems you don't need it at all. It also seems that you are
trying
to deduce things using some sort of woodoo already ;)
You might find this helpful (creates 2 visio controls, worksforme):

using AxMicrosoft.Office.Interop.VisOcx;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
private AxDrawingControl[] axDrawingControls;
public Form1()
{
int numberOfControls = 2;
this.axDrawingControls = new
AxDrawingControl[numberOfControls];
for (int i = 0; i < numberOfControls; ++i)
{
AxDrawingControl axDrawingControl = new
AxDrawingControl();
axDrawingControl.Enabled = true;
axDrawingControl.Name = "axDrawingControl" + i;
axDrawingControl.Location = new
System.Drawing.Point(0, i*100);
axDrawingControl.Size = new System.Drawing.Size(100,
100);
Controls.Add(axDrawingControl);
axDrawingControls = axDrawingControl;
}

InitializeComponent();
}
}
}

Kind regards.
 
A

ahmadka

Hey thanx dude...that worked!! Thankyou for taking me out of that sticky
spot....but I still dont know what was I doing wrong...the only thing I think
I didnt do is 'add' the new visio control to the Controls container....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top