VB Migration Partner

KNOWLEDGE BASE - Forms and controls

Previous | Index | Next 

[PRB] Setting the Visible=False for a Frame may cause spurious GotFocus, LostFocus, and Validate events

Here is a minor behavioral difference between VB6 and .NET. Say that you have a Frame control with a button on it that, when clicked, hides the Frame itself. Under VB6 this operation correctly moves the focus to the control “after” the Frame, according to the TabIndex order.

Under .NET, however, this operation moves the input focus to the next control inside the frame just before the entire frame becomes hidden. This additional input shift causes spurious GotFocus, LostFocus, and Validate events for such a control. Depending on the code in these event handlers, the migrated application might behave incorrectly or generate errors.

Worse, when the GotFocus event fires, the Frame’s Visible property uncorrectly returns the value True, even if the GotFocus event fired because the frame has become hidden.

Fortunately, this situation is quite rare and is unlikely to occur in most migrated applications, if your code misbehave for this reason, the recommended solution is that you set a Boolean variable inside the button’s Click event, and test this variable in the event handlers, as in this short example:

         Dim frameIsHidden As Boolean
         Private Sub cmdHide_Click()
             ' let event handlers know that the frame is hidden
             frameIsHidden  = True
             ' now  you can actually hide it
             Frame1.Visible  = False
         End Sub
         Private Sub txtField_GotFocus()
             ' ignore this event if the frame is hidden
             If  frameIsHidden Then Exit Sub
         End Sub
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