- 积分
- 0
- 在线时间
- 10 小时
- 主题
- 2
- 注册时间
- 2017-5-12
- 帖子
- 13
- 最后登录
- 2017-9-23
- 帖子
- 13
- 软币
- 110
- 在线时间
- 10 小时
- 注册时间
- 2017-5-12
|
public partial class TabControlEx : TabControl { Image backGroundImage; public TabControlEx() { InitializeComponent(); //重画TabControl base.SetStyle( ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true); base.UpdateStyles(); this.Alignment = TabAlignment.Bottom; this.Size = new Size(600,375); this.SizeMode = TabSizeMode.Fixed; // 大小模式为固定 //选项卡的大小 this.ItemSize = new Size(70, 20); // 设定每个标签的尺寸 //背景图片 backGroundImage = new Bitmap(this.GetType(), "backgroundimage.png"); } protected override void OnPaint(PaintEventArgs e) { for (int i = 0; i < this.TabCount; i++) { //画背景 e.Graphics.DrawImage(backGroundImage, this.GetTabRect(i)); if (this.SelectedIndex == i) { //画线的位置及大小 Rectangle rect = new Rectangle(this.GetTabRect(i).Location.X+4, this.GetTabRect(i).Location.Y + 1, 63, 17); e.Graphics.DrawRectangle(Pens.LightSlateGray, rect); //内框 //e.Graphics.DrawImage(backImage, this.GetTabRect(i)); } Rectangle bounds = this.GetTabRect(i); PointF textPoint = new PointF(); SizeF textSize = TextRenderer.MeasureText(this.TabPages[i].Text, this.Font); // 注意要加上每个标签的左偏移量X textPoint.X = bounds.X + (bounds.Width - textSize.Width) / 2; textPoint.Y = bounds.Bottom - textSize.Height - this.Padding.Y; // Draw highlights e.Graphics.DrawString( this.TabPages[i].Text, this.Font, SystemBrushes.ControlLightLight, // 高光颜色 textPoint.X, textPoint.Y-2); // 绘制正常文字 textPoint.Y--; e.Graphics.DrawString( this.TabPages[i].Text, this.Font, SystemBrushes.ControlText, // 正常颜色 textPoint.X, textPoint.Y-2); if (this.ImageList != null) { int index = this.TabPages[i].ImageIndex; string key = this.TabPages[i].ImageKey; Image icon = new Bitmap(1, 1); if (index > -1) { icon = this.ImageList.Images[index]; } if (!string.IsNullOrEmpty(key)) { icon = this.ImageList.Images[key]; } e.Graphics.DrawImage( icon, bounds.X + (bounds.Width - icon.Width) / 2, bounds.Top + this.Padding.Y); } } } }
|
|