473,748 Members | 4,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 InitializeCompo nent() call.

thanks for any assistance.
Dennis

using interop = System.Runtime. InteropServices ;

namespace TASAMS

{

[interop.ProgId( "TimeLineContro l"),

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

interop.ClassIn terface(interop .ClassInterface Type.AutoDispat ch),

interop.ComVisi ble(true)]

public class TimeLineControl : System.Windows. Forms.UserContr ol

{

....

}


Nov 16 '05 #1
4 9308
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*******@hotm ail.com> wrote in message
news:O4******** ******@TK2MSFTN GP15.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 InitializeCompo nent() call.

thanks for any assistance.
Dennis

using interop = System.Runtime. InteropServices ;

namespace TASAMS

{

[interop.ProgId( "TimeLineContro l"),

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

interop.ClassIn terface(interop .ClassInterface Type.AutoDispat ch),

interop.ComVisi ble(true)]

public class TimeLineControl : System.Windows. Forms.UserContr ol

{

....

}


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.c om> wrote
in message news:ex******** ******@TK2MSFTN GP14.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*******@hotm ail.com> wrote in message
news:O4******** ******@TK2MSFTN GP15.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 InitializeCompo nent() call.

thanks for any assistance.
Dennis

using interop = System.Runtime. InteropServices ;

namespace TASAMS

{

[interop.ProgId( "TimeLineContro l"),

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

interop.ClassIn terface(interop .ClassInterface Type.AutoDispat ch),

interop.ComVisi ble(true)]

public class TimeLineControl : System.Windows. Forms.UserContr ol

{

....

}

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.M yControl", "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*******@hotm ail.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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.c om> wrote
in message news:ex******** ******@TK2MSFTN GP14.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*******@hotm ail.com> wrote in message
news:O4******** ******@TK2MSFTN GP15.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 InitializeCompo nent() call.
>
> thanks for any assistance.
> Dennis
>
> using interop = System.Runtime. InteropServices ;
>
> namespace TASAMS
>
> {
>
> [interop.ProgId( "TimeLineContro l"),
>
> interop.Guid("1 24B9B07-35A7-4c72-B04B-3A04E42F1E07"),
>
> interop.ClassIn terface(interop .ClassInterface Type.AutoDispat ch),
>
> interop.ComVisi ble(true)]
>
> public class TimeLineControl : System.Windows. Forms.UserContr ol
>
> {
>
> ....
>
> }
>
>
>
>



Nov 16 '05 #4
Thanks Dmitriy

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om> wrote
in message news:ey******** ******@TK2MSFTN GP09.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.M yControl", "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*******@hotm ail.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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.c om> wrote in message news:ex******** ******@TK2MSFTN GP14.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*******@hotm ail.com> wrote in message
news:O4******** ******@TK2MSFTN GP15.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 InitializeCompo nent() call. >
> thanks for any assistance.
> Dennis
>
> using interop = System.Runtime. InteropServices ;
>
> namespace TASAMS
>
> {
>
> [interop.ProgId( "TimeLineContro l"),
>
> interop.Guid("1 24B9B07-35A7-4c72-B04B-3A04E42F1E07"),
>
> interop.ClassIn terface(interop .ClassInterface Type.AutoDispat ch),
>
> interop.ComVisi ble(true)]
>
> public class TimeLineControl : System.Windows. Forms.UserContr ol
>
> {
>
> ....
>
> }
>
>
>
>


Nov 16 '05 #5

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

Similar topics

1
3402
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 System.Web.UI.UserControl to my UserControl class (a.k.a MyUserControl). MyUserControl is only a .cs file with a class inheriting from System.Web.UI.UserControl. But, when I try to view the control in the Visual Studio designer it always pop me a window asking me if I...
1
2910
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 files. I have no problem using my .vb code behind file for my .aspx pages i just have to say <%@ Page Language="vb" Inherits="myCode" src="index.vb" %> in my aspx file and use Inherits Page in my .vb code behind file and everything is cool ...
1
1258
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? Henri
2
4633
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 for me! I apologize for the length of this posting, but I wanted to make sure that I get an answer other than "Hey man, just use LoadControl!", because this is not what I want. The Task: Isolate a collection of web forms which are created as
1
3021
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 have a usercontrol, the ascx is defined like this: <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Test.ascx.cs" Inherits="Spin.Test" %> <asp:Panel ID="Panel1" runat="server" Height="243px" Width="350px">
1
10802
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. Today, I wanted to access the home page of the application again with a browser. But instead of the proper page, I just got an ugly message: Server Error in '/' Application.
12
2209
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 server. It "serves" back the required control (either WebControl or UserControl) based on the contents of an xml file. The code in the webform places each control in a TableCell. My problem is that the control server works as far as returning the...
0
2094
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 UserControl? (Script attached to, and executed by, a UserControl embedded server control can ‘see’ the UserControl through the root document architecture. How to get the script to execute and ‘see’ other server controls in the...
0
1143
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 Sub btnSubmit(ByVal obj As Object, ByVal ea As EventArgs) lblMessage.Text = "UserName : " & uid.Text & "<br>Password : "
6
2758
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 file dependency and assign it to Dependency property.
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.