VB Migration Partner

KNOWLEDGE BASE - Forms and controls


Previous | Index | Next 

[PRB] The font of a control changes unexpectedly at runtime

VB6 and VB.NET greatly differ in the way they manage fonts in forms and controls. Under VB6 you can change the Font property of a form, a PictureBox, or another container control without affecting the font of child controls. In migrated VB.NET this isn’t true: any change in the Font property of a container affects the Font property of all child controls, unless you’ve specified a specific value for one or more font-related properties (FontName, FontSize, FontBold, and so forth).

In most circumstances this behavioral difference doesn’t affect the way migrated applications display their controls. If it does, however, you can easily work around this issue by invoking the FreezeControlsFont6 method for the container whose Font property will change during the form’s lifetime. You typically invoke this method in the handler for the Form_Load event:

        Private Sub Form_Load()
            '## InsertStatement FreezeControlsFont6(Me)
        End Sub

The FreezeControlsFont6 method (defined in the control support library) assigns a different Font object to each child control, so that child controls aren’t affected if a different value is later assigned to the container’s Font property.

In general you should pass the Me keyword (i.e. the reference to the current form or the current UserControl), so that the Font property of all child controls is affected. However, you can reduce the overhead of this method by specifying a container other than the form. For example, if your code modifies the Font property of a PictureBox and a Frame control (but not of the parent form), you can reduce the overhead by assigning only the Font property of the controls inside the PictureBox and Frame controls as follows:

        Private Sub Form_Load()
            '## InsertStatement FreezeControlsFont6(Picture1)
            '## InsertStatement FreezeControlsFont6(Frame1)
        End Sub

The FreezeControlsFont6 method is included in the VBMigrationPartner_Support module; if you add this file to the VB6 project you can avoid using the InsertStatement pragma and ensure that method and control names are spelled out correctly:

        ' this code assumes that VBMigrationPartner_SupportMethod module 
        ' is included in current project
        Private Sub Form_Load()
            FreezeControlsFont6 Me
        End Sub
Previous | Index | Next 




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