tabcontrol控件自定义,选项卡可以换图片,自己画线
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.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.Text, this.Font, SystemBrushes.ControlLightLight, // 高光颜色 textPoint.X, textPoint.Y-2); // 绘制正常文字 textPoint.Y--; e.Graphics.DrawString( this.TabPages.Text, this.Font, SystemBrushes.ControlText, // 正常颜色 textPoint.X, textPoint.Y-2); if (this.ImageList != null) { int index = this.TabPages.ImageIndex; string key = this.TabPages.ImageKey; Image icon = new Bitmap(1, 1); if (index > -1) { icon = this.ImageList.Images; } if (!string.IsNullOrEmpty(key)) { icon = this.ImageList.Images; } e.Graphics.DrawImage( icon, bounds.X + (bounds.Width - icon.Width) / 2, bounds.Top + this.Padding.Y); } } } }自定义,falsh控件不可以用了,只能这样了
页:
[1]