如何更改选项卡控件背景颜色 (VB.NET)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8412810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change Tab Control Background Color (VB.NET)
提问by C PWL
how can I change the grey part into white color? I want my tabcontrol filled with full white color.
如何将灰色部分更改为白色?我希望我的 tabcontrol 充满全白色。
So far what i did is like this:
到目前为止,我所做的是这样的:
Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
Dim g As Graphics = e.Graphics
Dim tp As TabPage = TabControl1.TabPages(e.Index)
Dim br As Brush
Dim sf As New StringFormat
Dim r As New RectangleF(e.Bounds.X, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height - 2)
sf.Alignment = StringAlignment.Center
Dim strTitle As String = tp.Text
'If the current index is the Selected Index, change the color
If TabControl1.SelectedIndex = e.Index Then
'this is the background color of the tabpage header
br = New SolidBrush(Color.White) ' chnge to your choice
g.FillRectangle(br, e.Bounds)
'this is the foreground color of the text in the tab header
br = New SolidBrush(Color.Black) ' change to your choice
g.DrawString(strTitle, TabControl1.Font, br, r, sf)
Else
'these are the colors for the unselected tab pages
br = New SolidBrush(Color.White) ' Change this to your preference
g.FillRectangle(br, e.Bounds)
br = New SolidBrush(Color.Black)
g.DrawString(strTitle, TabControl1.Font, br, r, sf)
End If
End Sub
and I also put this at PageLoad function:
我也把它放在 PageLoad 函数中:
TabControl1.DrawMode = TabDrawMode.OwnerDrawFixed
For Each tg As TabPage In TabControl1.TabPages
tg.BackColor = Color.White
Next
采纳答案by Prafulla
There is no property to do this. However it is possible by using something like this
没有财产可以做到这一点。但是可以通过使用这样的东西
http://dotnetrix.co.uk/tabcontrol.htm
http://dotnetrix.co.uk/tabcontrol.htm
All controls on this site are freely available under MIT license.
本网站上的所有控件均在 MIT 许可下免费提供。
回答by wpcoder
Spending fair time to research if someone find a solution; There could be some work around. But according to MSDN Ref.
花大量时间研究是否有人找到了解决方案;可能有一些解决方法。但根据MSDN 参考。
TabControl.BackColor Property
TabControl.BackColor 属性
NET Framework (current version) This API supports the product infrastructure and is not intended to be used directly from your code.
This member is not meaningful for this control.
Namespace: System.Windows.Forms Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
NET Framework(当前版本) 此 API 支持产品基础结构,不应直接从您的代码中使用。
此成员对于此控件没有意义。
命名空间:System.Windows.Forms 程序集:System.Windows.Forms(在 System.Windows.Forms.dll 中)
As far as I understand, this is adjustable from user's windows setting. (Highlight Color
) of TabControl
, Forms and other controls; otherwise MS could simply turn this property on.
据我了解,这可以从用户的 Windows 设置中进行调整。( Highlight Color
) of TabControl
、Forms 和其他控件;否则 MS 可以简单地打开此属性。