Create an ActiveX Control in .NET and use it under VB6

C

Captain Chaos

That's not the answer I want to hear :)

I am 1000% sure there may be a proper solution
but I only know a very dirty one that I don't like......

For example I could create a NET Window, put the NET Control in it.
The create a COM Interface.
Then Create a VB6 ActiveX Control an call the COM Interface.
Then open the Window, getting the Windows Handle of the Control
and place the Control via Windows API (setParent) in the VB6 ActiveX
Control.
 
C

Captain Chaos

Ok, i found some kind of solution myself:

First Create a COM Class with DOT NET.
Menu "Project" - "AddNew Item" - Com Class.

But the Code from there into your UserControl

It look something like this the:


<ComClass(UserControl1.ClassId, UserControl1.InterfaceId,
UserControl1.EventsId)> _
Public Class UserControl1
Inherits System.Windows.Forms.UserControl


#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "4E194D65-C09C-4378-B47F-CAAF521EB8EC"
Public Const InterfaceId As String =
"F9913483-3444-4989-A4D1-F1D4D23955BA"
Public Const EventsId As String = "F05903BF-31A7-47F6-AF5F-67C230D1F172"
#End Region

Windows Form Designer generated code

Public Sub Test()

End Sub

End Class

If you compile the whole thing you there is a *.TLB File created.

Now start VB6:

Make a reference to the TLB File.

Then in the VB 6 User Control you can load your DOT NET Control Dynamicly:

Dim vlob_UserCtrl As Object

Set vlob_UserCtrl = Controls.Add("ClassLibrary5.UserControl1", "HeadCtrl")
vlob_UserCtrl.Left = 0
vlob_UserCtrl.Top = 0
vlob_UserCtrl.ZOrder 0
vlob_UserCtrl.Visible = True


ClassLibrary5.UserControl1 = Namespace and Controlname of the DOT Net
Control
 
C

Captain Chaos

In Addition:

To Handle Events and Set/Get Properties use Code like this:


Dim vlob_UserCtrl As Object
Dim WithEvents vlob_UserCtrl2 As ClassLibrary5.UserControl1

Private Sub Command1_Click()

Set vlob_UserCtrl = Controls.Add("ClassLibrary5.UserControl1", "HeadCtrl")
vlob_UserCtrl.Left = 0
vlob_UserCtrl.Top = 0
vlob_UserCtrl.Height = 100
vlob_UserCtrl.ZOrder 0
vlob_UserCtrl.Visible = True

Set vlob_UserCtrl2 = vlob_UserCtrl.object

'With vlob_UserCtrl2 you can now handle the Events and set/Get
Properties/Call Methodes aso.

End Sub
 

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