tabcontron之边框颜色
前言
tabcontrol在c#中,边框颜色无法通过属性修改,只能通过代码实现`
提示:以下是本篇文章正文内容,下面案例可供参考
一、tabcontrol自带效果
1.边缘白色无法修改
2.切换栏按钮无法修改
二、操作步骤
1.修改属性
2.添加事件
2.添加事件代码
代码如下(示例):
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
//绘制背景平面
Rectangle rect = new Rectangle(0, 0, tabControl1.Width, tabControl1.Height); //获取背景区域
//Color backcolor = System.Drawing.Color.FromArgb(((int)(((byte)(54)))), ((int)(((byte)(97)))), ((int)(((byte)(135)))));
Color backcolor = System.Drawing.Color.LightSteelBlue; //获取背景颜色
Brush mybrushbj = new SolidBrush(backcolor); //定义背景画刷
Region region = new Region(rect);
e.Graphics.FillRegion(mybrushbj, region); //背景颜色修改
//对标签文字布局
StringFormat mystringformat = new StringFormat(); //定义选项卡文字格式类(居中)
mystringformat.LineAlignment = StringAlignment.Center;
mystringformat.Alignment = StringAlignment.Center;
Font font = new Font("微软雅黑", 13, FontStyle.Bold); //定义选项卡文字大小,样式
SolidBrush brbfont = new SolidBrush(Color.White); //定义选项卡文字颜色
//绘制字体
for (int i = 0; i < tabControl1.TabCount; i++)
{
Rectangle fontrect = tabControl1.GetTabRect(i);
e.Graphics.DrawString(tabControl1.TabPages[i].Text, font, brbfont, fontrect, mystringformat);
}
}
三:效果展示
已经和背景融为一体