create activeX (ocx equivalent) for Excel - is possible?


R

Rich P

I used to build little activeX/ocx controls in VB6 for Excel, Access
like a VB6 form with a textbox for some purpose (probably just testing).
I would compile these as .ocx files. In .net I have created a class
library control (no gui controls) that I would compile into a dll/tlb,
and using an interface (and making it com visible) in the .Net control I
could make a reference to this non gui .Net control in Access/Excel VBA
and communicate between the control and the client/subscriber (whatever
Access/Excel is supposed to be here).

Now I need to add a form to an ActiveX control to display some non
character data results on - like a canvas. I would be using this
control in Excel - basically minnie custom graphs (which there would be
lots of). Ideally, I would like to create this activeX control in C#,
but I have not had any luck using the ways that I am familiar with -
like a Windows Form Control Library project. Excel complains when I try
to add my control as an addin that it does not contain an automation
server, and if I try to make a reference to the dll - Excel says it is
not able to create this reference.

So before I dig up my old VB6 CD, is it possible to create an ActiveX
control for Excel of the type I describe in C#(2008, or 2005, 2003 I
have em all)? I need a control with a form/background where I pass data
to the control from Excel and then draw dots on. Any articles on
creating a com winform activeX control would be great.

Thanks,

Rich
 
Ad

Advertisements

R

Rich P

I found the answer to my question of "is there a .Net equivalent to
ocx?" in this article (and confirmed with related articles)

http://bytes.com/topic/c-sharp/answers/253895-creating-ocx-net

and the answer is that there is NO equivalent. Apparently, it is
possible to create non-gui .Net assemblies that can be used in a com
environment, but can't create gui .Net controls to be used in the com
environment. At least this is how I am interpreting the following
excerpt from this article:
While you can do COM-visible components in .NET, you unfortunately
cannot do OCX (ActiveX) *controls*.
<<
If your C# code is not UI-related, you can indeed compile and register
it as a COM-visible assembly, and then to create the visual part in,
say, Visual Basic 6, and to reference the C#-written COM DLL from the
VB6 project.
<<

Of course, this would be redundant. I guess I need to find my VB6 CD.

Rich
 
T

Tom Shelton

I found the answer to my question of "is there a .Net equivalent to
ocx?" in this article (and confirmed with related articles)

http://bytes.com/topic/c-sharp/answers/253895-creating-ocx-net

and the answer is that there is NO equivalent. Apparently, it is
possible to create non-gui .Net assemblies that can be used in a com
environment, but can't create gui .Net controls to be used in the com
environment. At least this is how I am interpreting the following
excerpt from this article:

While you can do COM-visible components in .NET, you unfortunately
cannot do OCX (ActiveX) *controls*.
<<

If your C# code is not UI-related, you can indeed compile and register
it as a COM-visible assembly, and then to create the visual part in,
say, Visual Basic 6, and to reference the C#-written COM DLL from the
VB6 project.
<<

Of course, this would be redundant. I guess I need to find my VB6 CD.

Rich

While designed for VB.NET - there is the windows forms interop toolkit:

http://www.microsoft.com/downloads/...C5-DC85-4065-9327-96801E57B81D&displaylang=en

This does allow you to create forms and controls that can be used by VB6.
 
Ad

Advertisements

R

Rich P

Interesting. Thanks. It sounds like this is exclusive to
VB.Net, which is OK for my purposes. I actually did start an ocx
project in VB6, and Access/Excel accepted it quite readily. But it is
the exercise of working with .net that motivates me to do it in .Net.
So, with this tool kit - I guess I need to install all 3 files? I plan
on doing that. And, does this still require using Interfaces like the
com-visible dll?

Additionally, I have been using my own homegrown guid getter string str1
= string.Format(guid).... for the interface ID

instead of regasm.exe

Any words of wisdom on this practice?

And lastly, the goal of my ocx is to display a series of dots
(circles/ellipses) in a graph like format and connected together in a
mini graph like background (the .Net form - or com form as it is in
VB6). I will be instantiating several dozen of these mini graphs in an
Excel worksheet. I think another alternative would be to display the
Excel worksheet within a .Net application and then I could use .Net
controls on that. Or I could display the Excel worksheet on an aspx
page and use aspx controls. Yes?

Rich
 

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