VB Migration Partner

KNOWLEDGE BASE - Forms and controls


Previous | Index | Next 

[PRB] Disabled controls and read-only TextBox controls appears with grayed background

In VB6, controls whose Enabled property is set to False, or controls that are hosted inside a container whose Enabled property is set to False, aren’t visually distinguishable from enabled controls. In VB.NET, however, disabled TextBox, ComboBox, ListBox controls have a light gray background color and a dark gray foreground color.

You can force controls on VB.NET forms to behave like their VB6 counterparts by calling the ConvertSystemColors6 method on a single control or on a container control. (This method is defined in the VBMigrationPartner_Support module and in the control support library.) The method doesn’t change the way the VB6 application behaves, yet it delivers the desired result once the application is converted to VB.NET:

        Private Sub Form_Load()
            ConvertSystemColors6 Me
            ' …
        End Sub

The ConvertSystemColors6 method affects only the BackColor property of disabled controls, but not their ForeColor property (which remains equal to dark gray), therefore the VB.NET code still behaves slightly differently from the original VB6 code even after applying this fix.

Be aware that there is a similar issue with TextBox and ComboBox controls whose Locked property is set to True. When these controls are converted to their VB.NET counterparts, their background color is set to light gray and their foreground color is set to dark gray. Unfortunately, you can’t force a different background color for .NET readonly controls, therefore the ConvertSystemColors6 method has no effect on such controls and there is no easy workaround for this issue.

Finally, we recommend that you use the ConvertSystemColors6 method only if it is of paramount importance that the VB.NET retains the appearance of the original VB6 code; .NET user interface guidelines mandate that disabled and read-only fields be grayed and you should violate these guidelines only if you have a serious reason to do so.

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