I am trying to set the disabled font characteristics for a Label Control. I can set all of the Font characteristics (size, bold, etc), but the color is overridden by the default windows behavior which seems to be one of these two colors:
The image below demonstrates the behavior -- Column 1 is Labels, Column 2 is TextBoxs, and Column 3 is ComboBoxes.
Edit -- Explaining the image: The first two rows are default styles for a label, textbox, and combobox. In the second two rows, I set the Background color to Red and Foreground to White. The disabled font style handling by Microsoft is inconsistent.
Have you tried implementing the EnabledChanged event? Or are you looking for more of a "styles" property on the control (as far as I know, they don't exist)?
For the textbox, you can set the readonly property to true while keeping the control enabled. You can then set the BackColor and ForeColor property to whatever you like. The user will still be able to click on the control and have a blinking cursor, but they won't be able to edit anything.
Not sure if this extrapolates out to other control types like combo boxes or whatnot as I haven't had a chance to experiment yet, but it's worth a shot.
Take a look at the ControlPaint.DrawStringDisabled method; it might be something helpful. I've used it when overriding the OnPaint event for custom controls.
ControlPaint.DrawStringDisabled(g, this.Text, this.Font, Color.Transparent,
new Rectangle(CustomStringWidth, 5, StringSize2.Width, StringSize2.Height), StringFormat.GenericTypographic);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With