Why doesn't BackColor work for TabControls in .NET?

If you use the standard .NET tab control for your tab pages and you try to change the look a bit, you can change the back color of the tab pages, but not for the tab control. The property is available, you can set it, but it has no effect. If you change the back color of the pages and not the tab control, it looks ... uhm is pretty ugly.

I know that Microsoft does not want it installed. MSDN : ' This property supports the .NET Framework and is not intended to be used directly from your code. This element does not make sense for this control. 'A color-only management property that supports the .NET framework? ... it's hard to believe.

I was hoping Microsoft would change it, but they did not. I created my own TabControl class that overrides the drawing method to fix this. But is this really the best solution?

What is the reason behind BackColor support failure for this control? What is your decision to fix this? Is there a better solution than overriding the paint method?

0
controls tabcontrol
source share
4 answers

The Rajesh blog solution is really useful, but it only colors the control tab. In my case, I had a tabcontrol on a different colored background. The tabs themselves were gray, which was not a problem, but the area to the right of the tabs was displayed as a gray bar.

To change this color to the background color, you need to add the following code to the DrawItem method (as described in the Rajesh solution). I am using VB.Net:

... Dim r As Rectangle = tabControl1.GetTabRect(tabControl1.TabPages.Count-1) Dim rf As RectangleF = New RectangleF(rX + r.Width, rY - 5, tabControl1.Width - (rX + r.Width), r.Height + 5) Dim b As Brush = New SolidBrush(Color.White) e.Graphics.FillRectangle(b, rf) ... 

Basically, you need to get a rectangle made on the right side of the last tab, on the right side of the tab control, and then fill it to the desired color.

+2
source share

The background color of the tab is apparently controlled by the OS display properties. In particular, under the "Appearance" tab, the Windows property and buttons (Windows XP). When installed in the Windows Classic style, the tab does not change color ever. When installed in the style of Windows XP, it at least changes from gray to white when it is selected. Therefore, it is impossible to control the background color - this is a function!

+1
source share

Thanks, Laura. You helped me on the right track. I already found an Oscar link, but did nothing for the strip at the end.

In the end, I had to change a little, because I needed a background image in the form to skip or the parent was something without a background image, backcolor. I also needed badges to show if they were present. I have a complete entry with all the code in the TabControl BackColor setup message .

0
source share

All Articles