为什么 BackColor 不适用于 .NET 中的 TabControls?
如果您在选项卡页中使用 .NET 中的标准选项卡控件,并且尝试稍微更改外观,那么您可以更改选项卡页的背景颜色,但不能更改选项卡控件的背景颜色。 该属性可用,您可以设置它,但没有任何效果。 如果您更改页面的背景颜色而不是选项卡控件的背景颜色,它看起来......呃相当难看。
我知道微软不希望它被设置。 MSDN:'此属性支持 . NET Framework 基础结构,并不打算直接从您的代码中使用。 该成员对于该控件没有意义。' 仅用于支持 .NET 基础结构的颜色的控件属性? ...难以置信。
多年来我希望微软能够改变它,但他们没有。 我创建了自己的 TabControl 类,它重写了 Paint 方法来解决这个问题。 但这真的是最好的解决方案吗?
该控件不支持 BackColor 的原因是什么? 您有什么解决方案来解决这个问题? 有没有比重写 Paint 方法更好的解决方案?
If you use the standard tab control in .NET for your tab pages and you try to change the look and feel a little bit then you are able to change the back color of the tab pages but not for the tab control. The property is available, you could set it but it has no effect. If you change the back color of the pages and not of the tab control it looks... uhm quite ugly.
I know Microsoft doesn't want it to be set. MSDN: 'This property supports the .NET Framework infrastructure and is not intended to be used directly from your code. This member is not meaningful for this control.' A control property just for color which supports the .NET infrastructure? ...hard to believe.
I hoped over the years Microsoft would change it but they did not. I created my own TabControl class which overrides the paint method to fix this. But is this really the best solution?
What is the reason for not supporting BackColor for this control? What is your solution to fix this? Is there a better solution than overriding the paint method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
谢谢,劳拉。 你帮助我走上了正轨。 我已经找到了奥斯卡提供的链接,但这对最后的漫画没有任何作用。
最后,我不得不做出很大的改变,因为我需要表单上有一个背景图像来渗透,或者如果父级是没有背景图像的东西,则需要背景色。 我还需要图标来显示它们是否存在。 我有一个完整的文章,其中包含我的 TabControl BackColor 修复帖子。
Thanks, LauraM. You helped get me on the right track. I had already found the link Oskar provided but that didn't do anything for the strip at the end.
In the end, I had to change quite a bit because I needed a background image on the form to bleed through or if the parent was something without a background image, the backcolor. I also needed icons to show if they were present. I have a full write-up with all the code in my TabControl BackColor fix post.
选项卡的背景颜色似乎由操作系统的显示属性控制。 特别是在外观选项卡、Windows 和按钮属性 (Windows XP) 下。 当设置为 Windows 经典样式时,选项卡永远不会改变颜色。 当设置为Windows XP风格时,选择时至少会从灰色变为白色。 所以无法控制背景颜色是一个特性!
The background color of the tab seems to be controlled by the OS's Display Properties. Specifically the under the appearance tab, Windows and buttons property (Windows XP). When set to Windows Classic style, the tab doesn't change color ever. When set to Windows XP style, it at least changes from gray to white when selected. So not being able to control the background color is a feature!
Rajesh 博客中的解决方案确实很有用,但它仅对控件的选项卡部分进行着色。 就我而言,我有一个不同颜色背景的选项卡控件。 选项卡本身是灰色的,这不是问题,但选项卡右侧的区域显示为灰色条带。
要将此颜色更改为背景颜色,您需要将以下代码添加到 DrawItem 方法(如 Rajesh 解决方案中所述)。 我正在使用 VB.Net:
基本上,您需要将最后一个选项卡的右侧制成的矩形添加到选项卡控件的右侧,然后将其填充为所需的颜色。
The solution in Rajesh's blog is really useful, but it colours the tab part of the control only. In my case I had a tabcontrol on a different coloured background. The tabs themselves were grey which wasn't a problem, but the area to the right of the tabs was displaying as a grey strip.
To change this colour to the colour of your background you need to add the following code to the DrawItem method (as described in Rajesh's solution). I'm using VB.Net:
Basically you need to get the rectangle made of the right hand side of the last tab to the right hand side of the tab control and then fill it to your desired colour.