Is it possible to use Windows Forms controls directly on a VB6 form?

Viewed 555

Is it possible to use a .NET Windows Forms control directly in a VB6 form?

The goal here would be to use the more up to date .NET controls in a legacy VB6 application. We already have a mixed .NET / VB6 environment.

  • I am aware of the Microsoft InteropForms Toolkit but it is described as being used for exporting custom usercontrols to VB6 from .NET. This doesn't seem to provide for preexisting controls (but I could be wrong).

  • I have tried to simply reference System.Windows.Forms.tlb in a VB6 project as a component library - but it does not allow this to be selected, which seems to imply it has no ActiveX controls inside it.

I'm aware you can easily do the reverse - eg use a VB6 usercontrol on a .NET winforms form. That's not what I need.


You can reference the System.Windows.Forms assembly in a normal way from VB6 - and wind up with a line such as the following in your VBP:

Reference=*\G{215D64D2-031C-33C7-96E3-61794CD1EE61}#2.4#0#C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Windows.Forms.tlb#System_Windows_Forms

but this doesn't provide access to place controls on a form.

1 Answers

I did that before. I created a control (with the forms control you want use) in .net (exported to tlb using InteropFormsToolkit) and created a vb6 control where I put that .net control. It was necessary to map all the properties, events and methods that I wanted to use. In forms vb6 I added this vb6 control, with the .net encapsulated. It worked!

Related