国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#更改tabControl選項卡顏色的方法

2020-01-24 01:15:01
字體:
來源:轉載
供稿:網友

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

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類的構造函數中添加下列語句:

this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;this.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  = 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);}

更多關于C#相關內容感興趣的讀者可查看本站專題:《C#數據結構與算法教程》、《C#常見控件用法教程》、《C#面向對象程序設計入門教程》及《C#程序設計之線程使用技巧總結

希望本文所述對大家C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临潭县| 沙湾县| 兰坪| 贺州市| 连南| 萨迦县| 交城县| 广东省| 临夏县| 阳高县| 惠州市| 固镇县| 兴宁市| 周宁县| 南乐县| 时尚| 海南省| 太谷县| 青龙| 安福县| 伊吾县| 鸡泽县| 凤阳县| 丽江市| 三门县| 金堂县| 康保县| 呼玛县| 星座| 上饶县| 寻甸| 登封市| 武穴市| 铜陵市| 武强县| 巴南区| 长海县| 清丰县| 德化县| 唐河县| 全南县|