最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#更改tabControl選項(xiàng)卡顏色的方法

 更新時(shí)間:2016年03月03日 10:09:32   作者:Microblue  
這篇文章主要介紹了C#更改tabControl選項(xiàng)卡顏色的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了C#更改tabControl選項(xiàng)卡顏色的的具體步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了C#更改tabControl選項(xiàng)卡顏色的方法。分享給大家供大家參考,具體如下:

private void Form1_Load(object sender, EventArgs e)
{
  this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
  this.tabControl1.DrawItem += new DrawItemEventHandler(this.tabControl1_DrawItem);
}
private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
  StringFormat sf = new StringFormat();
  sf.LineAlignment = StringAlignment.Center;
  sf.Alignment = StringAlignment.Center;
  if (e.Index == tabControl1.SelectedIndex)
    e.Graphics.FillRectangle(Brushes.Red, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
  else
    e.Graphics.FillRectangle(Brushes.White, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
  e.Graphics.DrawString(((TabControl)sender).TabPages[e.Index].Text,
  System.Windows.Forms.SystemInformation.MenuFont, new SolidBrush(Color.Black), e.Bounds, sf);
}

1.在Form類的構(gòu)造函數(shù)中添加下列語(yǔ)句:

this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
this.tabControl1.DrawItem += new DrawItemEventHandler(this.tabControl1_DrawItem);

2.實(shí)現(xiàn)下列函數(shù):

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  = 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);
}

更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#常見(jiàn)控件用法教程》、《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》及《C#程序設(shè)計(jì)之線程使用技巧總結(jié)

希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

汉沽区| 若尔盖县| 德清县| 米易县| 斗六市| 大冶市| 贺州市| 邹平县| 东光县| 若羌县| 池州市| 石阡县| 鄂伦春自治旗| 岳池县| 齐齐哈尔市| 四会市| 忻州市| 罗源县| 盐山县| 宝山区| 焦作市| 乐亭县| 玉屏| 平度市| 巩留县| 政和县| 五莲县| 乐山市| 财经| 麟游县| 栾川县| 澄迈县| 甘洛县| 日土县| 牙克石市| 望谟县| 弋阳县| 贵溪市| 静宁县| 聂拉木县| 韩城市|