开始我用代码把tabcontrol的选项卡颜色重绘了,但是重绘完了之后我发现tabcontrol的边框有白色的边界,这个边界怎么去掉啊,求高手指点。重绘代码是我从网上找的,做了一些简单的修改,如下:
public partial class frmProfile : Form
{
public frmProfile()
{
InitializeComponent();
this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
this.tabControl1.DrawItem +=new DrawItemEventHandler(this.tabControl1_DrawItem);
} private void frmProfile_Load(object sender, EventArgs e)
{
this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
this.tabControl1.DrawItem += new DrawItemEventHandler(this.tabControl1_DrawItem);
tabControl1.TabPages[0].BackColor = Color.LightGray; } private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
if (e.Index == tabControl1.SelectedIndex)
{
e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds.X - 1, e.Bounds.Y - 2, tabControl1.ItemSize.Width, tabControl1.ItemSize.Height + 2);
}
else
{
e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds.X - 1, e.Bounds.Y - 2, tabControl1.ItemSize.Width, tabControl1.ItemSize.Height + 2);
}
e.Graphics.FillRectangle(Brushes.LightGray, tabControl1.TabPages.Count * tabControl1.ItemSize.Width + 1, 0, tabControl1.Width - tabControl1.TabPages.Count * tabControl1.ItemSize.Width, tabControl1.ItemSize.Height + 2);
e.Graphics.DrawString(((TabControl)sender).TabPages[e.Index].Text, System.Windows.Forms.SystemInformation.MenuFont, new SolidBrush(Color.Black), e.Bounds, sf);
}c#tabcontrol
public partial class frmProfile : Form
{
public frmProfile()
{
InitializeComponent();
this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
this.tabControl1.DrawItem +=new DrawItemEventHandler(this.tabControl1_DrawItem);
} private void frmProfile_Load(object sender, EventArgs e)
{
this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
this.tabControl1.DrawItem += new DrawItemEventHandler(this.tabControl1_DrawItem);
tabControl1.TabPages[0].BackColor = Color.LightGray; } private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
if (e.Index == tabControl1.SelectedIndex)
{
e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds.X - 1, e.Bounds.Y - 2, tabControl1.ItemSize.Width, tabControl1.ItemSize.Height + 2);
}
else
{
e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds.X - 1, e.Bounds.Y - 2, tabControl1.ItemSize.Width, tabControl1.ItemSize.Height + 2);
}
e.Graphics.FillRectangle(Brushes.LightGray, tabControl1.TabPages.Count * tabControl1.ItemSize.Width + 1, 0, tabControl1.Width - tabControl1.TabPages.Count * tabControl1.ItemSize.Width, tabControl1.ItemSize.Height + 2);
e.Graphics.DrawString(((TabControl)sender).TabPages[e.Index].Text, System.Windows.Forms.SystemInformation.MenuFont, new SolidBrush(Color.Black), e.Bounds, sf);
}c#tabcontrol
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货