473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How do I make a C# UserControl into an OCX file for VB6 use?

I have a pretty complex control which use to be a C# windows form that I am
trying to make into a control that can be dragged onto a VB6 form.

I was able to make it into a com class that I could then go to VB6 and add
the reference and call the object there without any problems.

When I try to make it into a UserControl, I get it to build and it registers
itself during the build with no errors BUT I can not add the dll to the vb6
project. I can add the dll to another C# project and all the form
(usercontrol) works as it should with the grid and toolbar buttons doing
their thing as planned.

below is the top section of the class diff.

The contructor doesn't do anything but the InitializeComponent() call.

thanks for any assistance.
Dennis

using interop = System.Runtime.InteropServices;

namespace TASAMS

{

[interop.ProgId("TimeLineControl"),

interop.Guid("124B9B07-35A7-4c72-B04B-3A04E42F1E07"),

interop.ClassInterface(interop.ClassInterfaceType. AutoDispatch),

interop.ComVisible(true)]

public class TimeLineControl : System.Windows.Forms.UserControl

{

....

}


Nov 16 '05 #1
4 9271
Hi Dennis,

You cannot turn a C# user control to an OCX - this possibility, as far as I
remember, was considered and partially implemented in early beta versions of
the Framework, but later Microsoft decided not to support it in the release
version. Still, you have a workaround (BTW it is widely used by developers
writing add-ins for VS .NET) - the so-called shim control. It is a free
small ActiveX control provided by Microsoft (not sure where to look for it
on the Microsoft website but I'm sure there are even several versions in the
"Files" section of this group: http://groups.yahoo.com/groups/vsnetaddin)

The ActiveX has a couple of public methods designed to tell the ActiveX
which class from which assembly to host inside it. So you drag the ActiveX
to a VB6 form and then invoke its HostUserControl method - and voila, you
have a .NET control in your VB6 app.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Dennis Burdett" <de*******@hotmail.com> wrote in message
news:O4**************@TK2MSFTNGP15.phx.gbl...
I have a pretty complex control which use to be a C# windows form that I am
trying to make into a control that can be dragged onto a VB6 form.

I was able to make it into a com class that I could then go to VB6 and add
the reference and call the object there without any problems.

When I try to make it into a UserControl, I get it to build and it
registers
itself during the build with no errors BUT I can not add the dll to the
vb6
project. I can add the dll to another C# project and all the form
(usercontrol) works as it should with the grid and toolbar buttons doing
their thing as planned.

below is the top section of the class diff.

The contructor doesn't do anything but the InitializeComponent() call.

thanks for any assistance.
Dennis

using interop = System.Runtime.InteropServices;

namespace TASAMS

{

[interop.ProgId("TimeLineControl"),

interop.Guid("124B9B07-35A7-4c72-B04B-3A04E42F1E07"),

interop.ClassInterface(interop.ClassInterfaceType. AutoDispatch),

interop.ComVisible(true)]

public class TimeLineControl : System.Windows.Forms.UserControl

{

....

}


Nov 16 '05 #2
thanks Dmitriy,

I have been trying to figure out how to do this most of the day and can get
it to build (at least the shim part) and I am then able to add the new dll
to the VB6 project form BUT I guess I am just not understanding what or how
to make the changes my code to get it to actually add my UserControl to the
host shim dll so it will run my stuff within vb.

Dennis
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:ex**************@TK2MSFTNGP14.phx.gbl...
Hi Dennis,

You cannot turn a C# user control to an OCX - this possibility, as far as I remember, was considered and partially implemented in early beta versions of the Framework, but later Microsoft decided not to support it in the release version. Still, you have a workaround (BTW it is widely used by developers
writing add-ins for VS .NET) - the so-called shim control. It is a free
small ActiveX control provided by Microsoft (not sure where to look for it
on the Microsoft website but I'm sure there are even several versions in the "Files" section of this group: http://groups.yahoo.com/groups/vsnetaddin)

The ActiveX has a couple of public methods designed to tell the ActiveX
which class from which assembly to host inside it. So you drag the ActiveX
to a VB6 form and then invoke its HostUserControl method - and voila, you
have a .NET control in your VB6 app.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Dennis Burdett" <de*******@hotmail.com> wrote in message
news:O4**************@TK2MSFTNGP15.phx.gbl...
I have a pretty complex control which use to be a C# windows form that I am trying to make into a control that can be dragged onto a VB6 form.

I was able to make it into a com class that I could then go to VB6 and add the reference and call the object there without any problems.

When I try to make it into a UserControl, I get it to build and it
registers
itself during the build with no errors BUT I can not add the dll to the
vb6
project. I can add the dll to another C# project and all the form
(usercontrol) works as it should with the grid and toolbar buttons doing
their thing as planned.

below is the top section of the class diff.

The contructor doesn't do anything but the InitializeComponent() call.

thanks for any assistance.
Dennis

using interop = System.Runtime.InteropServices;

namespace TASAMS

{

[interop.ProgId("TimeLineControl"),

interop.Guid("124B9B07-35A7-4c72-B04B-3A04E42F1E07"),

interop.ClassInterface(interop.ClassInterfaceType. AutoDispatch),

interop.ComVisible(true)]

public class TimeLineControl : System.Windows.Forms.UserControl

{

....

}

Nov 16 '05 #3
Dennis,

As far as I remember, this should look like something like this:

Sub Form_Load
Dim objUserControl As Object
Set objUserControl =
objShimControl.HostUserControl("MyNamespace.MyCont rol", "MyAssembly,
Version=1.0.0.0, Culture=Neutral, PublicKeyToken=null")
End Sub

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Dennis Burdett" <de*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
thanks Dmitriy,

I have been trying to figure out how to do this most of the day and can
get
it to build (at least the shim part) and I am then able to add the new dll
to the VB6 project form BUT I guess I am just not understanding what or
how
to make the changes my code to get it to actually add my UserControl to
the
host shim dll so it will run my stuff within vb.

Dennis
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:ex**************@TK2MSFTNGP14.phx.gbl...
Hi Dennis,

You cannot turn a C# user control to an OCX - this possibility, as far as

I
remember, was considered and partially implemented in early beta versions

of
the Framework, but later Microsoft decided not to support it in the

release
version. Still, you have a workaround (BTW it is widely used by
developers
writing add-ins for VS .NET) - the so-called shim control. It is a free
small ActiveX control provided by Microsoft (not sure where to look for
it
on the Microsoft website but I'm sure there are even several versions in

the
"Files" section of this group: http://groups.yahoo.com/groups/vsnetaddin)

The ActiveX has a couple of public methods designed to tell the ActiveX
which class from which assembly to host inside it. So you drag the
ActiveX
to a VB6 form and then invoke its HostUserControl method - and voila, you
have a .NET control in your VB6 app.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Dennis Burdett" <de*******@hotmail.com> wrote in message
news:O4**************@TK2MSFTNGP15.phx.gbl...
>I have a pretty complex control which use to be a C# windows form that I am > trying to make into a control that can be dragged onto a VB6 form.
>
> I was able to make it into a com class that I could then go to VB6 and add > the reference and call the object there without any problems.
>
> When I try to make it into a UserControl, I get it to build and it
> registers
> itself during the build with no errors BUT I can not add the dll to the
> vb6
> project. I can add the dll to another C# project and all the form
> (usercontrol) works as it should with the grid and toolbar buttons
> doing
> their thing as planned.
>
> below is the top section of the class diff.
>
> The contructor doesn't do anything but the InitializeComponent() call.
>
> thanks for any assistance.
> Dennis
>
> using interop = System.Runtime.InteropServices;
>
> namespace TASAMS
>
> {
>
> [interop.ProgId("TimeLineControl"),
>
> interop.Guid("124B9B07-35A7-4c72-B04B-3A04E42F1E07"),
>
> interop.ClassInterface(interop.ClassInterfaceType. AutoDispatch),
>
> interop.ComVisible(true)]
>
> public class TimeLineControl : System.Windows.Forms.UserControl
>
> {
>
> ....
>
> }
>
>
>
>



Nov 16 '05 #4
Thanks Dmitriy

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:ey**************@TK2MSFTNGP09.phx.gbl...
Dennis,

As far as I remember, this should look like something like this:

Sub Form_Load
Dim objUserControl As Object
Set objUserControl =
objShimControl.HostUserControl("MyNamespace.MyCont rol", "MyAssembly,
Version=1.0.0.0, Culture=Neutral, PublicKeyToken=null")
End Sub

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Dennis Burdett" <de*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
thanks Dmitriy,

I have been trying to figure out how to do this most of the day and can
get
it to build (at least the shim part) and I am then able to add the new dll to the VB6 project form BUT I guess I am just not understanding what or
how
to make the changes my code to get it to actually add my UserControl to
the
host shim dll so it will run my stuff within vb.

Dennis
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote in message news:ex**************@TK2MSFTNGP14.phx.gbl...
Hi Dennis,

You cannot turn a C# user control to an OCX - this possibility, as far as
I
remember, was considered and partially implemented in early beta
versions of
the Framework, but later Microsoft decided not to support it in the

release
version. Still, you have a workaround (BTW it is widely used by
developers
writing add-ins for VS .NET) - the so-called shim control. It is a free
small ActiveX control provided by Microsoft (not sure where to look for
it
on the Microsoft website but I'm sure there are even several versions
in the
"Files" section of this group:
http://groups.yahoo.com/groups/vsnetaddin)
The ActiveX has a couple of public methods designed to tell the ActiveX
which class from which assembly to host inside it. So you drag the
ActiveX
to a VB6 form and then invoke its HostUserControl method - and voila, you have a .NET control in your VB6 app.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Dennis Burdett" <de*******@hotmail.com> wrote in message
news:O4**************@TK2MSFTNGP15.phx.gbl...
>I have a pretty complex control which use to be a C# windows form that I am
> trying to make into a control that can be dragged onto a VB6 form.
>
> I was able to make it into a com class that I could then go to VB6
and add
> the reference and call the object there without any problems.
>
> When I try to make it into a UserControl, I get it to build and it
> registers
> itself during the build with no errors BUT I can not add the dll to

the > vb6
> project. I can add the dll to another C# project and all the form
> (usercontrol) works as it should with the grid and toolbar buttons
> doing
> their thing as planned.
>
> below is the top section of the class diff.
>
> The contructor doesn't do anything but the InitializeComponent() call. >
> thanks for any assistance.
> Dennis
>
> using interop = System.Runtime.InteropServices;
>
> namespace TASAMS
>
> {
>
> [interop.ProgId("TimeLineControl"),
>
> interop.Guid("124B9B07-35A7-4c72-B04B-3A04E42F1E07"),
>
> interop.ClassInterface(interop.ClassInterfaceType. AutoDispatch),
>
> interop.ComVisible(true)]
>
> public class TimeLineControl : System.Windows.Forms.UserControl
>
> {
>
> ....
>
> }
>
>
>
>


Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: S Guiboud | last post by:
I want to subclass the System.Web.UI.UserControl to make a common control for my site. Then, when I create a new UserControl from the Visual Studio I changed the base class...
1
by: Michael Evanchik | last post by:
Tying not to spaghetti code which seems to be easy to do in .net, im trying to do my main .net html in index.aspx, use repeated .net html in an .ascx files and all code im doing in .vb code behind...
1
by: Henri | last post by:
I guess I could do that with an .ascx UserControl file using Page.LoadControl(), but as I want to render a complete page inside a mail body, loading an .aspx might be nicer... Any suggestion? ...
2
by: Sascha | last post by:
Hi there, I searched carefully through the web before finally deciding to post this message, because I could not find a solution for my problem. Hopefully someone will have a hint or explanation...
1
by: Philipp Lenz | last post by:
I'm very confused about how this works, all the tutorials out there show me how to apply a skin to a webcontrol, but I want to know how I can access the components of a control....for example: I...
1
by: urs | last post by:
Two days ago, I built an ASP.NET 2.0 application and published it on a shared IIS 6 Web server. After publishing, and during the whole day, it worked fine. The server remained untouched since....
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
0
by: oliver | last post by:
QUESTION: How to access an object embedded in a UserControl through Javascript file? Another way to ask this question: How to execute script from a UserControl, accessing other objects in that...
0
by: Arpan | last post by:
I have created the following UserControl (the file is named LoginForm.ascx): <script language=VB runat="server"> Public UName As String Public UPwd As String Public BColor As String Public...
6
by: Rolf Welskes | last post by:
Hello, I want to partial cache by using a UserControl. Now I have a file dependency. In msdn I see it is not possible to do it the same way as in a page. The only information is to create a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.