登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

BCB-DG's Blog

...

 
 
 

日志

 
 

改變tabControl標簽顏色  

2010-04-14 09:43:41|  分类: DotNet |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
1:
tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
tabControl1.DrawItem += new DrawItemEventHandler(this.tabControl1_DrawItem);

2:
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;
    }
    else
    {
        fntTab = e.Font;
        bshBack = new SolidBrush(Color.Blue);
        bshFore = new SolidBrush(Color.Black);
    }
    string tabName = 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);
}


public Form1()
{
    InitializeComponent();
    tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
    tabControl1.DrawItem += new DrawItemEventHandler(this.tabControl1_DrawItem);
}

private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{    
    Brush bshFore;
    Brush bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, SystemColors.Control, SystemColors.Control, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
    if (e.Index == tabControl1.SelectedIndex)
        bshFore = Brushes.Red;
    else
        bshFore = Brushes.Black;
    string tabName = 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, e.Font, bshFore, recTab, sftTab);
}
  评论这张
 
阅读(3419)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018