VB6 vs VB.NET controls - UserControl object

This section describes the differences between VB6 and .NET controls and the problems you can find in migrating VB6 applications with user-interface. The differences that are common to most controls are described in the Controls (general) section.

For a list of differences between VB6 and VB.NET language, see here.

Unless otherwise stated, VB Migration Partner fully supports all the Visual Basic 6 features mentioned in this page. It is worth noticing that names of properties and methods are preserved, which ensures that those even late-bound references work correctly after the migration to VB.NET. For more information, please read the manual and the knowledge base section.

UserControl object

Many of the differences among the VB6 and VB.NET UserControl classes are similar to the differences between the VB6 and VB.NET Form classes. They are explained in depth in the section devoted to the Form object. The current section deals with the properties, methods, and events that are specific to the UserControl object.

AccessKeys property, AccessKeyPress event

Under VB6 you can assign the AccessKey property to specify which hotkeys the end user can use to move the input focus to the UserControl; when one of the specified hotkeys is actually pressed, the UserControl object receives the AccessKeyPress event. This mechanism is used by controls that are rendered exclusively by means of graphic and that contain no Label, Button, or other controls that support the Caption property. VB.NET UserControls don’t support a built-in mechanism for trapping hotkeys.

VB Migration Partner partially supports this rarely-used feature; the property retains its value between assignments but has no effect on the runtime behavior. The AccessKeyPress event is also implemented but is never actually fired. In practice, its only purpose is to allow the UserControl to compile correctly.

Ambient property and AmbientChanged event

.NET controls expose neither the Ambient property nor the AmbientChanged event.

When migrating VB6 code that relies on the Ambient property, in most cases you can use the corresponding property of the object returned by the Container property. For example, the Ambient.BackColor and Ambient.Font VB6 properties map to Container.BackColor and Container.Font VB.NET properties.

This holds true also for the Ambient.ForeColor and Ambient.RightToLeft properties, which map to Container.ForeColor and Container.RightToLeft, respectively. In some cases, the name of the container property is different. For example, the Ambient.DisplayName property maps to Container.Name.

The Ambient.LocaleID VB6 property can be replaced by the CurrentInfo.CurrentUICulture.LCID property under VB.NET. A few VB6 ambient properties have no corresponding value in the .NET Framework, namely MessageReflect, Palette, ShowGrabHandles, ShowHatching, and UIDead.

VB Migration Partner partially supports the Ambient property, which returns an instance of the VB6Ambient class. This class exposes all the properties of the VB6 Ambient object, so that no compilation errors occurs. However, only a subset of the Ambient properties are actually supported, namely: BackColor, DisplayAsDefault, DisplayName, ForeColor, Font, ForeColor, LocaleID, RightToLeft, ScaleUnits, and UserMode.

In addition, the AmbientChanged event is supported only for the BackColor, ForeColor, and Font properties.

AsyncRead and CancelAsyncRead methods, AsyncReadComplete and AsyncReadProgress events

Under VB6 a UserControl can read a property asynchronously using the AsyncRead method, or cancel an asynchronous read operation by means of the CancelAsyncRead method. When the read operation is progressing one or more AsyncReadProgress events are fired; when the read operation is complete, an AsyncReadComplete event is fired. This feature is especially useful for UserControls that are meant to be hosted inside an HTML page, where the actual value of the property – for example, an image – must be read via the Internet.

VB.NET doesn’t directly support asynchronous properties. It is indeed possible to perform any read operation in asynchronous way, but many manual edits should be performed.

VB Migration Partner supports these members, but no asynchronous behavior is implemented. The AsyncRead method reads a property synchronously and then fires the AsyncReadComplete event. The CancelAsyncRead method does nothing. The AsyncReadProgress event is never fired.

CanPropertyChange and PropertyChanged methods

Under VB6 a UserControl should call the CanPropertyChange method before assigning a different value to a property, and the PropertyChanged method after changing the value of a property. These methods are intercepted by the VB6 runtime to implement data-bound UserControls, among other things.

VB.NET doesn’t support anything similar to these methods. Implementing a .NET UserControl that supports data-binding requires many manual changes.

VB Migration Partner supports these methods. In current implementation, the CanPropertyChange method always return True, whereas the PropertyChanged method does nothing. The main purpose of these methods is to avoid compilation and runtime errors in migrated VB.NET applications.

ContainedControls collection

In VB.NET it isn’t possible to discern between controls that were placed on the usercontrol’s surface at design-time (when the usercontrol is defined) and those that were added after placing the usercontrol on a .NET form’s surface.

VB Migration Partner partially supports the ContainedControls collection; however, this collection always contains the same items as the standard Controls collection.

ContainerHwnd property

This property isn’t supported under VB.NET. You can replace it with code that returns the Handle property of the container, something like

        Dim handle As Integer = DirectCast(Me.Parent, Control).Handle.ToInt32()

DataMember property

This property isn’t supported under VB.NET.

VB Migration Partner implementation of this property as an empty member that always returns Nothing.

EnterFocus, ExitFocus events

Under VB6 these events fire when the input focus enters and exits the UserControl, respectively. These events correspond to the Enter and Leave events in VB.NET.

EventsFrozen method

Code running inside a VB6 UserControl can use the EventsFrozen method to ensure that it is safe to trigger an event. VB.NET doesn’t support this method.

VB Migration Partner partially supports the EventsFrozen method. This method returns True when the UserControl is being loaded and in a few other occasions. However, it isn’t guaranteed to be perfectly equivalent to the original VB6 method.

Extender property

Under VB6 the Extender property returned a reference to a special “extender” wrapper that was built the first time an ActiveX was dropped on a form’s surface. The Extender object had typically all the members of the original ActiveX plus all the members added by the container (i.e. the VB6 IDE), such as Left and Top. The definition of the extender object was stored in a file with .OCA extension.

The Extender property isn’t supported under VB.NET, because no wrapper is created when a UserControl is dropped on a Windows Forms surface. You can usually delete the reference to the Extender property. For example, the following VB6 code:

        Me.Extender.Left = Me.Extender.Left + 100

can be translated into VB.NET as

        Me.Left = Me.Left + 100

VB Migration Partner supports the Extender property, which simply returns a reference to the UserControl itself.

HitBehavior property, HitTest event

VB6 developers can use the HitBehavior property and the HitTest event to implement non-rectangular UserControls or controls with “holes” inside them. VB.NET doesn’t support this property and requires completely different programming techniques to implement such irregular UserControls, for example using Windows region objects.

VB Migration Partner supports this property; it always returns the value 1; attempts to assign a different value are ignored (or throw an exception if the VB6Config.ThrowOnUnsupportedMembers property is True). The HitTest event is implemented but is never fired.

HyperLink property

VB6 developers can use the Hyperlink property to manage jumps to a different HTML page, when the UserControl is hosted inside the browser. This functionality isn’t available under VB.NET.

VB Migration Partner implements this property but it always returns Nothing. In practice, it only serves to avoid errors when compiling the UserControl.

KeyPreview property

This property isn’t available under VB.NET. The easiest way to simulate its behavior is to intercept the KeyDown, KeyUp, and KeyPress events of all the controls on the UserControl, using code like this:

        For Each ctrl As Control In Me.Controls
            AddHandler ctrl.KeyDown, AddressOf Control_KeyDown
            AddHandler ctrl.KeyUp, AddressOf Control_KeyUp
            AddHandler ctrl.KeyPress, AddressOf Control_KeyPress

VB Migration Partner fully supports the KeyPreview property; if the input focus is currently on a UserControl’s child control this property is True, any keyboard operation fires an event in the UserControl class first, and then in the child control that currently has the focus.

Locked and Size properties

If a VB6 user control exposes a property named Locked, such property should be renamed when the user control is converted to VB6, because it would interfere with Visual Studio 2005’s designer. Similarly, if the user control exposes a member named Size, it should be renamed because it would confuse Visual Studio 2005’s designer.

VB Migration Partner renames such members as Locked6 and Size6, respectively.

Hide and Show events

The .NET UserControl class doesn’t support these events. Instead, you should trap the VisibleChanged event to detect the moment when the control becomes visible or invisible.

VB Migration Partner fully supports the Hide and Show events.

InvisibleAtRuntime property

VB6 UserControl support this property; by setting this property to True you make the control always invisible at runtime, as is the case of components such as the Timer.

VB.NET doesn’t directly support this property. A UserControl that is always invisible at runtime should be implemented as a class that inherits from System.ComponentModel.Component instead of System.Windows.Forms.UserControl.

VB Migration Partner supports this property and generates a UserControl whose Visible property is always False. Any attempt to set this property to True – either at design-time or runtime – throws an exception.

Palette and PaletteMode properties

VB.NET user controls don’t support the Palette and PaletteMode properties, and there is no direct way to simulate these VB6 properties.

The VB6UserControl class in the VB Migration Partner’s support library exposes the Palette and PaletteMode properties, but they always returns Nothing and 0-Halftone, respectively; attempts to assign different value are ignored (or throw a runtime exception if the VB6Config.ThrowOnUnsupportedMembers property is set to True). These properties are marked as obsolete and a migration warning is emitted when these properties are referenced in code.

ParentControls collection

Under VB6 this property returns the controls contained in the form that contains the current UserControl. The ParentControlsType property exposed by this collection permits to determine whether the actual controls or the Extender wrappers of those controls should be returned.

VB.NET doesn’t support anything similar to the ParentControls collection. VB Migration Partner returns a collection that includes all the controls contained in the parent form, including the form itself. The returned collection exposes the ParentControlsType property, but assigning a value to this property has no effect on the items in the collection itself.

Picture property

VB.NET doesn’t support the Picture property. You can achieve the same effect by using the BackgroundImage property.

PropertyPages property

VB6 developers can use the PropertyPages to associate a given PropertyPage object to a UserControl. The .NET Framework doesn’t support property pages, hence this property isn’t available under VB.NET.

VB Migration Partner supports the PropertyPages property, but it always returns an empty strings and all assignments to it are ignored. In practice, it only serves to ensure that the UserControl compiles with no errors.

Runtime-only properties

A VB6 user control can include one or more properties that are available only at runtime and that shouldn’t appear in the property window. By convention, such a property should raise error 382 or 387 in the Property Get procedure, as in:

        Property Get hWnd() As Long
            If Not Ambient.UserMode Then Err.Raise 382
            ' …
        End Property

During the conversion to VB.NET, such properties should be marked with the Browsable(False) attribute to hide them in the property window, and with the DesignSerializationVisibility(DesignerSerializationVisibility.Hidden) attribute to avoid persistence in the designer. VB Migration Partner correctly detects this situation and generates these attributes as needed.

Follow Francesco Balena on VB6 migration’s group on


Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.

Code Architects and its partners offers remote and onsite migration services.

More details

Subscribe to our free newsletter for useful VB6 migration tips and techniques.


To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice

A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial

The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote

Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers