Active TabPage has same color as my controls
I have made a TabControl and want to use some controls (labels, textboxes, buttons and combobox drop-downs). The problem is that when I select a tab, the default background开发者_高级运维 color is not the same as the default background color of the form the controls used to be on. The color of the tab and the controls are too similar and it doesn't look good.
I have looked, but people seem to say that it's impossible to color tabs. What is a good solution to this? Should I put some kind of frame, label or something else inside the tab to make the background darker?
It's easy to get your tab pages to use the same background color as your form:
Make sure that the
TabPage
you want to change is visible in the designer. Click on it to select it.In the Properties Window, find the
UseVisualStyleBackColor
property, and set it toFalse
.
And as a bonus, once you've set this property to False
, you can specify any background color that you want for the TabPage
using its BackColor
property.
The reason that this works is that you're forcing the tab page not to render with visual styles (i.e., themes as defined by Windows). The default theme actually paints tab pages a slightly lighter shade of the color used to paint other 3D elements (like forms and buttons). The problem (under the Aero theme in particular) is that the color of the standard 3D elements is so light already that the tab pages almost look white!
If you're satisfied with the contrast of the controls against the standard background color of your form, I suggest that you simply set the UseVisualStyleBackColor
property to False
and leave it at that without specifying a custom background color. Respecting the user's default theme is generally the best practice, rather than trying to skin an application yourself.
EDIT: Note that this will not change the color of the tabs themselves at the top of the TabControl
. To do that, you're going to have to specify it as owner-drawn and handle its DrawItem
event, forcing you to do all of the painting yourself. In most cases, however, this is not necessary.
精彩评论