By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,122 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,122 IT Pros & Developers. It's quick & easy.

creating an activeX component at runtime

P: n/a
Hi,

I have a C# application (VS2005) with Microsoft Mappoint activeX control on
a form. At a certain moment I want to create a second one temporary in code.
This seems not to work, when I try to access it I have an InvalidActiveXState
Exception.

I cannot find mutch on the web about this Invalid State of a component
except that it is invalid (what the Exception already describe). So I hope
someone here knows ?

It cannot be difficult to create an ActiveX component at runtime ? Are there
special things to do with it except calling the constructor with New ?

--
rgds, Wilfried
http://www.mestdagh.biz
Aug 18 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Wilfried,

I'm not sure exactly what you have to do, but, if I was facing this, I
would look at the area in the designer code and see how it is instantiating
the control, and see if there is a difference in the way that you are doing
it, versus how the designer is doing it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Wilfried Mestdagh" <Wi**************@discussions.microsoft.comwrote in
message news:3C**********************************@microsof t.com...
Hi,

I have a C# application (VS2005) with Microsoft Mappoint activeX control
on
a form. At a certain moment I want to create a second one temporary in
code.
This seems not to work, when I try to access it I have an
InvalidActiveXState
Exception.

I cannot find mutch on the web about this Invalid State of a component
except that it is invalid (what the Exception already describe). So I hope
someone here knows ?

It cannot be difficult to create an ActiveX component at runtime ? Are
there
special things to do with it except calling the constructor with New ?

--
rgds, Wilfried
http://www.mestdagh.biz

Aug 18 '06 #2

P: n/a
Wilfried Mestdagh wrote:
Hi,

I have a C# application (VS2005) with Microsoft Mappoint activeX control on
a form. At a certain moment I want to create a second one temporary in code.
This seems not to work, when I try to access it I have an InvalidActiveXState
Exception.

I cannot find mutch on the web about this Invalid State of a component
except that it is invalid (what the Exception already describe). So I hope
someone here knows ?

It cannot be difficult to create an ActiveX component at runtime ? Are there
special things to do with it except calling the constructor with New ?
Hi,

from my experience this can come from one or both of two things.

A lot of ActiveX controls require a call to BeginInit before you access
its properties:

AxHost activeX = ...;
activeX.BeginInit()
// do something
activeX.EndInit();

The second thing is that some ActiveX controls need to have a parent to
work correct. (After all they are ActiveX controls).

AxHost activeX = ...;
activeX.BeginInit()

// parent the control
Controls.Add(activeX);

activeX.EndInit();

This however will make the control visible.

HTH,
Andy
Aug 18 '06 #3

P: n/a
Hi,

Thank you. It was the Controls.Add() that did it. I set Visible to false and
it is ok too. I use it in a using block to make suer it is disposed.

--
rgds, Wilfried
http://www.mestdagh.biz
Aug 19 '06 #4

P: n/a
Wilfried Mestdagh wrote:
Hi,

Thank you. It was the Controls.Add() that did it. I set Visible to false and
it is ok too. I use it in a using block to make suer it is disposed.
Hi,

if you are using .NET 1.1: We have found a memory leak when we dispose
ActiveX controls. Depending on the size and type of your ActiveX and how
often you create/dispose it, you might want to do something about it.

The ActiveX hooks the VisibleChanged event of the main form when added
to another control and does not unhook it on Dispose(). This means that
the ActiveX will not be garbage collected as long as the main form
lives. If your ActiveX releases all resources on dispose properly, you
only will only notice a increase on the GC Handles.

One solution would be to keep he control creates and invisible. Another
one is to unhook the event using reflection.

This issue seems to be fixed in .NET 2.0.
Cheers,
Andy
Aug 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.