C#更改tabControl選項(xiàng)卡顏色的方法
本文實(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ù)中添加下列語句:
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#常見控件用法教程》、《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》及《C#程序設(shè)計(jì)之線程使用技巧總結(jié)》
希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C# Char結(jié)構(gòu)中IsLetterOrDigit(Char)的方法詳解
這篇文章給大家介紹了C#的Char 結(jié)構(gòu)的IsLetterOrDigit(Char)的方法,并通過代碼示例給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-02-02c# winform異步不卡界面的實(shí)現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于c# winform異步不卡界面的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用c#具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07用C#獲取硬盤序列號(hào),CPU序列號(hào),網(wǎng)卡MAC地址的源碼
用C#獲取硬盤序列號(hào),CPU序列號(hào),網(wǎng)卡MAC地址的源碼...2007-03-03c#簡(jiǎn)單工廠、工廠方法與抽象工廠的區(qū)別分析
看了網(wǎng)絡(luò)上很多關(guān)于設(shè)計(jì)模式的方法,有的模式看起來相似,但本質(zhì)還是區(qū)別很大的.像簡(jiǎn)單工廠,工廠方法和抽象工廠就有很明顯的區(qū)別.2013-03-03C#/VB.NET實(shí)現(xiàn)將XML轉(zhuǎn)為PDF
可擴(kuò)展標(biāo)記語言(XML)文件是一種標(biāo)準(zhǔn)的文本文件,它使用特定的標(biāo)記來描述文檔的結(jié)構(gòu)以及其他特性。本文將利用C#實(shí)現(xiàn)XML文件轉(zhuǎn)PDF?,需要的可以參考一下2022-03-03C#自定義鼠標(biāo)拖拽Drag&Drop效果之基本原理及基本實(shí)現(xiàn)代碼
拖拽效果無論是在系統(tǒng)上、應(yīng)用上、還是在網(wǎng)頁上,拖拽隨處可見,下面通過本文介紹下C#自定義鼠標(biāo)拖拽Drag&Drop效果之基本原理及基本實(shí)現(xiàn)代碼,需要的朋友可以參考下2022-04-04