【发布时间】:2012-08-06 05:01:05
【问题描述】:
前
|Tab1|Tab2|Tab3| { }
| |
| |
| |
| |
|_____________________|
我可以更改Tab 的backcolor 和forecolor.. 但我想更改那个{} 的颜色--> 空白空间是否可以这样做。 ..它显示默认的winforms颜色..帮助我在dis..
private void Form1_Load(object sender, EventArgs e)
{
}
private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Font fntTab;
Brush bshBack;
Brush bshFore;
if ( e.Index == this.tabControl1.SelectedIndex)
{
fntTab = new Font(e.Font, FontStyle.Bold);
bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, SystemColors.Control, SystemColors.Control, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
bshFore = Brushes.Black;
//bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.LightSkyBlue , Color.LightGreen, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
//bshFore = Brushes.Blue;
}
else
{
fntTab = e.Font;
bshBack = new SolidBrush(Color.Red);
bshFore = new SolidBrush(Color.Aqua);
//bshBack = new SolidBrush(Color.White);
//bshFore = new SolidBrush(Color.Black);
}
string tabName = this.tabControl1.TabPages[e.Index].Text;
StringFormat sftTab = new StringFormat();
e.Graphics.FillRectangle(bshBack, e.Bounds);
Rectangle recTab = e.Bounds;
recTab = new Rectangle( recTab.X, recTab.Y + 4, recTab.Width, recTab.Height - 4);
e.Graphics.DrawString(tabName, fntTab, bshFore, recTab, sftTab);
}
【问题讨论】:
-
我不认为标准的 .NET TabControl 允许您将选项卡右侧的这个“可用空间”设置为特定的背景颜色 - 它是透明的并且只显示表单的背景颜色。如果你真的需要这个,你必须找到另一个支持这个功能的 TabControl
-
将外观属性更改为“正常”,它将更改为透明
-
有更多充分的理由不这样做而不是这样做。
-
@marc_s:OP 正在将他的选项卡控件 DrawMode 设置为 OwnerDrawFixed 以自定义选项卡控件的样式。但是,这样做不再将背景空白空间设置为透明,而是将其设置为 system.control
标签: c# winforms tabs tabcontrol