Resources

VB6 vs VB.NET controls - MDIForm 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.





MDIForm object

Arrange method

The VB6 Arrange method corresponds to the VB.NET LayoutMdi method.



AutoShowChildren property

In VB6 you can set the AutoShowChildren property of an MDI form to True, to ensure that all MDI child forms become visible as soon as they are loaded. No such a property exists in VB.NET and you have to implement this behavior programmatically.

VB Migration Partner fully supports this property.



ActiveForm property

The ActiveForm property isn’t supported and corresponds to the ActiveMdiChild property under VB.NET.

VB Migration Partner fully supports the ActiveForm property; instead of returning a Form object, it returns an Object value, so that statements that rely on late binding work as in the original VB6 application, for example:

        If TypeOf ActiveForm Is frmDocument Then
            ActiveForm.DisplayDocument    ' this relies on late binding
        End If


BackColor property

The VB.NET form exposes the BackColor property, but this property isn’t functional if the form works as an MDI container.

The reason for the different behavior is that .NET MDI forms contain an additional child control of type MdiClient. This control fills the visible portion of the form background, thus hiding the “true” form background. As a matter of fact, you can change the background of a .NET MDI form by setting the BackColor property of such an MdiClient control. The following VB.NET code shows how to implement this technique:

        Dim mdiClient As MdiClient
        For Each ctrl As Control in Me.Controls
            mdiClient = TryCast(ctrl, MdiClient)
            If mdiClient IsNot Nothing Then Exit For
        Next
        If mdiClient IsNot Nothing Then mdiClient.BackColor = Color.Red

VB Migration Partner fully supports the BackColor property in MDI forms.



Click, DblClick, MouseDown, MouseMove, MouseUp

A VB6 MDI form raises mouse events when the user clicks or moves the mouse on the form’s background area. Conversely, no mouse event is triggered by a .NET MDI form.

The reason for the different behavior is that .NET MDI forms contain an additional child control of type MdiClient. This control fills the visible portion of the form background, thus hiding the “true” form background. Mouse activity is routed to this MdiClient control, not the parent form, therefore you should listen to events coming from the MdiClient control. The following code shows a simple technique to solve this problem:

        Dim mdiClient As MdiClient
        For Each ctrl As Control in Me.Controls
            mdiClient = TryCast(ctrl, MdiClient)
            If mdiClient IsNot Nothing Then Exit For
        Next
        If mdiClient IsNot Nothing Then
            ' ClickHandler and MouseMoveHandler methods must abide by .NET event syntax
            AddHandler mdiClient.Click, AddressOf ClickHandler
            AddHandler mdiClient.MouseMove, AddressOf MouseMoveHandler
        End If

VB Migration Partner fully supports all mouse events in MDI forms, without the need to manually wire the event handlers to the hidden MdiClient control.



Picture property

The Picture property of a VB6 form broadly maps to the BackgroundImage property of a VB.NET. However, setting the BackgroundImage property of an MDI Form has no effect under .NET.

The reason for the different behavior is that .NET MDI forms contain an additional child control of type MdiClient. This control fills the visible portion of the form background, thus hiding the “true” form background. As a matter of fact, you can change the background of a .NET MDI form by setting the BackgroundImage property of such an MdiClient control. The following VB.NET code shows how to implement this technique:

        Dim mdiClient As MdiClient
        For Each ctrl As Control in Me.Controls
            mdiClient = TryCast(ctrl, MdiClient)
            If mdiClient IsNot Nothing Then Exit For
        Next
        If mdiClient IsNot Nothing Then mdiClient.BackgroundImage = theImageToBeLoaded

VB Migration Partner fully supports the Picture property in MDI forms.



ScrollBars property

The ScrollBars property isn’t supported and broadly corresponds to the AutoSize property of a VB.NET form.

However, notice that there are two important differences you should account for. First, the default value of the ScrollBars property is True in VB6, whereas the default value of the AutoSize property is False under VB.NET. Second, any assignment to the AutoSize property resets the IsMdiContainer property, therefore you should always save and restore the value of the IsMdiContainer property when setting the AutoSize property, as in this code:

        Dim saveValue As Boolean = Me.IsMdiContainer
        Me.AutoSize = True
        Me.IsMdiContainer = saveValue

VB Migration Partner fully supports the ScrollBars property, so that the migrated code is guaranteed to work correctly even if the form is accessed in late-bound code.







Follow Francesco Balena on VB6 migration’s group on

LinkedIn





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.

newsletter



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