Referencing an ActiveX control in VB.NET

  • Thread starter Thread starter Ken Breit
  • Start date Start date
K

Ken Breit

I have an ActiveX control that I would like to make available from any form
in my application. I figured the best way was to create a reference to it,
and then have a module that will create the instince and assign all of the
properties to the control. This is a control that I did not write, it was
purchased from a vendor. Here is what I have done.

In the references section of my project I have added the ocx.
I then go to a code module, and declare a variable and assign it to the
control reference, along with the class that it has available (through
intellisence)
However, when I try to instantiate the control the class is not available in
intellisense, only an interface and another class that isn't relevant to
what I am doing.

If I use this control on a form, it works fine. However, I wan't the form
to be allowed to be closed.
The control uses the comm port, so I don't want to have to manage opening
and closing the control on each form.
The only other solution I can think of is to have a hidden form that has the
control on it.

I have found some documentation on msdn that talks about using Tlbimp, but
it states that I have to be the author of the control to make it work.

Am I barking up the wrong tree here, and going in the wrong direction, or is
what I am trying to do possible.

TIA
Ken Breit
 
Look in your windows Forms Desinger Generated code for the instance
reference of the active x control...

copy that code to your module...

=)
 
Thanks, that worked great. I actually had to add the control to the form,
and then it created the references for me. No that the dll is crated I will
just be able to add it to any project.

Thanks,
Ken
 
As always, happy to help. =)

Ken Breit said:
Thanks, that worked great. I actually had to add the control to the form,
and then it created the references for me. No that the dll is crated I will
just be able to add it to any project.

Thanks,
Ken
 
Oops. Now when I try to use it when it is not on a form, I get an unhandled
exception error (InvalidActiveXStateException) when I try to assign a
property.
Do I have to do something to put the control in a paticular state. In
looking in the form designer code it there are a number of properties that
get assigned, but are not available, such as ocxstate. I am able to assign
the enable property a value, but when I try to assign a property such as
comm port, it comes back with the error. Any ideas?

Thanks,
Ken
 
Hi,

It has to be sited on a form to reference it. The form DOES NOT have to be
displayed. This is "by design," AFAIK.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
Back
Top