VB Migration Partner

KNOWLEDGE BASE - Forms and controls

Previous | Index | Next 

[INFO] Controlling the GotFocus and MouseDown event sequence

A key difference between VB6 and VB.NET controls is in the event sequence that they fire when the end user moves the input focus to a control. In such circumstances, VB6 controls fire the MouseDown event and then the GotFocus event, whereas .NET controls do exactly the opposite: they fire the GotFocus event and then the MouseDown event.

Most often than not, this difference is negligible. However, in some cases the code in the GotFocus handler uses one or more variables that have been set in the MouseDown handler. You can force the support library to fire the MouseDown and GotFocus events in the same order as VB6, by setting the VB6Config.FocusEventSupport static property to True:

        ' put this statement in Sub Main
        VB6Config.FocusEventSupport = True

We recommend that you don’t set the FocusEventSupport property to True unless really necessary, because this setting adds overhead to the standard event dispatching process and might cause other minor annoyances.

Unfortunately, the FocusEventSupport property is of limited use in some cases. Consider the following VB6 code:

        ' select the textbox contents when the control gets the focus
        Private Sub Text1_GotFocus()
            Text1.SelStart = 0
            Text1.SelLength = Len(Text1.Text)
        End Sub

You will notice that this code doesn’t behave exactly as in VB6. More precisely:

  1. if the FocusEventSupport property is False (the default), the GotFocus event fires before the .NET Framework can process the mouse action, regardless of whether you have defined a handler for the MouseDown event; the click nullifies the code in the GotFocus handler, and the control contents doesn’t appear to be selected.
  2. If the FocusEventSupport property is True, then the GotFocus event fires after the .NET Framework has processed the mouse action and the contents in the control appears to be selected. However, the .NET Framework hasn’t processed yet the button release action, and as a result the control contents might appear to be selected only partially, depending on where the mouse button is released.
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