Interop UserControls are Windows Forms controls created in C# that can be used on Visual Basic 6.0 forms. They allow you to add .NET functionality to a Visual Basic 6.0 application without the need for an Interop form. In Multiple Document Interface (MDI) applications Interop UserControls can be placed directly on a Visual Basic 6.0 MDI child form, solving the limitation of not being able to use Interop forms as an MDI child.

Interop UserControls are created in C# by using a VB6 Interop UserControl project template, essentially a Windows Control project that includes code to marshal common properties, define some common Visual Basic 6.0 methods, and automatically register the control for COM interop. When the control is built in Visual Studio .NET it is registered; you can then add it to the Visual Basic 6.0 toolbox and use it like any Visual Basic 6.0 control.

The Interop UserControl provides full Intellisense support when used in Visual Basic 6.0. As with Interop Forms, if you reference the Interop Forms Toolkit you can also raise application-level events and access globals via the InteropToolbox and InteropGlobals classes.

Ensuring Binary Compatibility

In order to avoid breaking changes and ensure binary compatibility between different versions, the following practices are recommended:

a) Ensure that all new public methods/properties/events are added at the bottom of the class.

b) Avoid changing the names of assemblies or the class names of Interop UserControls/InteropForms.

c) When specifying a new member with the same name as a member in the base class, you must use either the new or override keyword.

d) You must make sure that any data types can be marshalled correctly.

Custom events can also be added and raised using the event keyword. For more information, see How To: Handle Interop UserControl Events.

You can also create a control library containing multiple Interop UserControls, creating additional controls in your Interop UserControl project by using the VB6 Interop UserControl item template.

Interop UserControl limitations

Interop UserControls are .NET controls, and as such there are a few limitations when using them in Visual Basic 6.0.
  • You should not show a .NET form from an Interop UserControl. The .NET form will not close if the parent form is closed first, and tabbing on the .NET form will not work. [Opening forms modally seems to work just fine. I haven't observed any tabbing issues either, but I've preserved this statement from the original toolkit docs. --HolisticDeveloper]
  • Code in the GotFocus and LostFocus events of the Interop UserControl defined in Visual Studio will never be executed; the intrinsic GotFocus and LostFocus events on an instance of the control in Visual Basic 6.0 will still work. If you need to handle the events in .NET, use the Enter and Leave events instead.
  • Control arrays of Interop UserControls are not supported.
  • If a MenuStrip control is used on an Interop UserControl, menu merging with WindowList enabled MDI forms is not supported.
  • There are known issues when using an ElementHost control for Windows Presentation Foundation (WPF) on an Interop UserControl; it can only be hosted on a Windows Form. While the scenario is technically unsupported, it is possible to get this to work.
  • Interop UserControls can only be hosted on Visual Basic 6.0 forms, they cannot be placed on ActiveX controls or in any other type of host (for example Microsoft Office).

For More Information

The following topics provide more information about creating and using Interop UserControls.

How To: Create an Interop UserControl

How To: Handle Interop UserControl Events

How To: Debug a Hybrid Application

How To: Deploy A Hybrid Application

Walkthrough Creating and Consuming an Interop User Control

Last edited Jan 16, 2012 at 5:22 AM by HolisticDeveloper, version 6


No comments yet.