471,071 Members | 8,731 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

creating an activeX component at runtime

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
4 6615
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
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
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
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.

Similar topics

1 post views Thread by Mattt | last post: by
19 posts views Thread by Steve | last post: by
1 post views Thread by Raed Sawalha | last post: by
15 posts views Thread by Carlos Lozano | last post: by
1 post views Thread by Rocio | last post: by
6 posts views Thread by hufaunder | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.