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