WinForm Button on a black background appears invisible with Visual Styles disabled
-
29-04-2021 - |
Question
i drop a Button
on a black Form
. The button appears fine at design time:
The button also appears fine at runtime (with Visual Styles enabled):
But the button draws completely wrong with visual styles disabled:
How to fix?
Bonus Chatter
- When dropping a
Button
on a black form, the button'sBackColor
sets itself to black - By default a
Button
dropped on a "normal" colored form has aBackColor
of Transparent - Setting the
Button
BackColor
toTransparent
doesn't fix it
Solution
I know this is an old post, but in case someone else comes across it, I managed to solve the issue in my program. In your Program.cs
page (or whatever it's been renamed to), ensure you've called Application.EnableVisualStyles before calling Run
.
Application.EnableVisualStyles();
Application.Run(new Form1());
Also ensure that the button's UseVisualStyleBackColor
property is set to true
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow