Search code examples
vb.netcomvb6visual-studio-2015interop

Creating COM usercontrol for VB6 with VS2015 RC


I would like to create a usercontrol in VS2015 RC (VB.NET) and use it in VB6.

Most articles talking about such a scenario are pretty aged.

I have just tried the following:

In VS2015 RC (Visual Basic.NET), I have created a new usercontrol and set its property to "COM visible" and compiled a x86 version of it.

However, I could not use the resulting DLL in VB6, the error was "The file can't be referenced".

I can reference the .tlb but I think that does not help me, or does it?

Can anybody lend a helping hand here?

Thank you.


Solution

  • Yieah!!! I got it. I had to reference the .tlb, then in VB6 I said:

    Option Explicit
    
    Private MyCtrl As VBControlExtender
    
    Private Sub Form_Load()
        Set MyCtrl = Controls.Add("ctrl.UserControl1", "ctrl", Me)
    End Sub
    
    Private Sub Form_Resize()
        MyCtrl.Left = 100
        MyCtrl.Width = Me.Width - 300
        MyCtrl.Top = 100
        MyCtrl.Height = Me.Height - 700
        MyCtrl.Visible = True
    End Sub