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

Referencing an ActiveX control in VB.NET

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Look in your windows Forms Desinger Generated code for the instance
reference of the active x control...

copy that code to your module...

=)
"Ken Breit" <kd********@ascentmedianospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

Nov 20 '05 #2

P: n/a
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
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.com...
Look in your windows Forms Desinger Generated code for the instance
reference of the active x control...

copy that code to your module...

=)
"Ken Breit" <kd********@ascentmedianospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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


Nov 20 '05 #3

P: n/a
As always, happy to help. =)

"Ken Breit" <kd********@ascentmedianospam.com> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
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
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.com...
Look in your windows Forms Desinger Generated code for the instance
reference of the active x control...

copy that code to your module...

=)
"Ken Breit" <kd********@ascentmedianospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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



Nov 20 '05 #4

P: n/a
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


"Ken Breit" <kd********@ascentmedianospam.com> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
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
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.com...
Look in your windows Forms Desinger Generated code for the instance
reference of the active x control...

copy that code to your module...

=)
"Ken Breit" <kd********@ascentmedianospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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



Nov 20 '05 #5

P: n/a
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.
Nov 20 '05 #6

P: n/a
Thanks.

PS - loved your book

"Dick Grier" <di**************@msn.com> wrote in message
news:%2*****************@TK2MSFTNGP10.phx.gbl...
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.

Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.