VB Migration Partner

KNOWLEDGE BASE - Forms and controls

Previous | Index | Next 

[PRB] The Default and Cancel properties of a VB6UserControl object don’t behave like in VB6

VB6 and VB.NET implement default and cancel buttons in radically different ways: VB6 uses the Default and Cancel properties applied to the button, whereas VB.NET uses the AcceptButton and CancelButton properties exposed by the parent form. VB Migration Partner’s support library fills the gap by providing the Default and Cancel properties in both Command button controls.

VB6 also provides the ability to defined user controls that behave like push buttons. This can be achieved by setting the user control’s design-time DefaultCancel property to True. When migrating such user controls, VB Migration Partner generates a class that exposes the Default and Cancel properties.

This way to mimic VB6’s behavior is nearly perfect, but there are a few cases when manual fixes are required:

a) if a form contains multiple user controls that behave like push buttons, the Default (or Cancel) and if these user controls contain a button whose Default (or Cancel) property is set to True, then the default (or cancel) push button for the form depends on the order in which the user controls are added to the form’s Controls collection. If you notice that the form displays the wrong default button, you should re-assign the Default property of the user control that must work as the default control:

        Private Sub Form_Load() Handles MyBase.Load
            Me.myUserControl1.Default = True
            Me.myUserControl1.Cancel = True
        End Sub

b) if a user control with DefaultCancel=True contains a command button, setting the Default (or Cancel) property of this button to True affects the AcceptButton (or CancelButton) property of the parent form, which ultimately makes the form behave differently from the original VB6 code. Therefore, the code in the user control should avoid setting the Default or Cancel property of a child button if the user control isn’t the default or cancel button on its parent form.

        ' inside a user control
        If Me.Parent.AcceptButton IsNot Nothing AndAlso _
              Me.Parent.AcceptButton.Parent Is Me Then
            ' the current default button on the parent form belongs to this
            ' user control, therefore we can proceed with the assignment
            Me.Command1.Default  = True
        End If
Previous | Index | Next 

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