TabControl控件自定义样式
TabControl控件自定义样式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace testTabFlash { public partial class Form1 : Form { public Form1() { InitializeComponent(); this .tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed; this .tabControl1.DrawItem += new DrawItemEventHandler( this .tabControl1_DrawItem); } private void Form1_Load( object sender, EventArgs e) { } private void tabControl1_DrawItem( object sender, System.Windows.Forms.DrawItemEventArgs e) { Font fntTab; Brush bshBack; Brush bshFore; if (e.Index == this .tabControl1.SelectedIndex) //当前Tab页的样式 { 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 //其余Tab页的样式 { 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); } } } |
posted on 2010-05-19 13:07 Yuxiaoshan 阅读(862) 评论(0) 编辑 收藏 举报
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步