自定义控件代码如下:

using System.Drawing;
using System.Windows.Forms; namespace Demo.UC
{
public class KKTab : TabControl
{
private int IconWOrH = 16;
private Image icon = null; public KKTab()
: base()
{
this.DrawMode = TabDrawMode.OwnerDrawFixed; icon = Demo.Properties.Resources.close;
IconWOrH = icon.Width;
IconWOrH = icon.Height;
} protected override void OnDrawItem(DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Rectangle r = GetTabRect(e.Index);
if (e.Index == this.SelectedIndex) //当前选中的Tab页,设置不同的样式以示选中
{
Brush selected_color = Brushes.SteelBlue; //选中的项的背景色
g.FillRectangle(selected_color, r); //改变选项卡标签的背景色
string title = this.TabPages[e.Index].Text;
g.DrawString(title, this.Font, new SolidBrush(Color.Black), new PointF(r.X , r.Y + 5));//PointF选项卡标题的位置
r.Offset(r.Width - IconWOrH, 2);
g.DrawImage(icon, new Point(r.X, r.Y));//选项卡上的图标的位置 fntTab = new System.Drawing.Font(e.Font, FontStyle.Bold);
}
else//非选中的
{
Brush selected_color = Brushes.AliceBlue; //选中的项的背景色
g.FillRectangle(selected_color, r); //改变选项卡标签的背景色
string title = this.TabPages[e.Index].Text+" ";
g.DrawString(title, this.Font, new SolidBrush(Color.Black), new PointF(r.X , r.Y + 5));//PointF选项卡标题的位置
r.Offset(r.Width - IconWOrH, 2);
g.DrawImage(icon, new Point(r.X, r.Y));//选项卡上的图标的位置
}
} protected override void OnMouseClick(MouseEventArgs e)
{
Point point = e.Location;
Rectangle r = GetTabRect(this.SelectedIndex);
r.Offset(r.Width - IconWOrH - 3, 2);
r.Width = IconWOrH;
r.Height = IconWOrH;
if (r.Contains(point)) this.TabPages.RemoveAt(this.SelectedIndex);
}
}
}

注意:使用方式:界面加载需处理TabPage Text属性

 foreach (TabPage item in this.kkTab1.TabPages)
{
item.Text = item.Text + " ";
}

运行效果如下:

最新文章

  1. javascript语言理解
  2. POJ1703Find them, Catch them[种类并查集]
  3. MAXIMO-修改菜单
  4. Oracle 修改一行数据内存主要变化
  5. c++普通高精除单精
  6. 利用DataTable快速批量导数据
  7. SQL通用查询
  8. SQL中的模糊查询
  9. Vijos P1521 跳舞 贪心
  10. 灵感闪现 篇 (一) 2d场景 3d 效果
  11. BOM之history对象(转)
  12. ERP管理员培训报道
  13. 从setTimeout看js函数执行
  14. Bootstrap3 表格-响应式表格
  15. 【移动开发】自定义ProgressBar
  16. Markdown编辑器editor.md的使用---markdown上传图片
  17. Django学习笔记(5)——cookie和session
  18. [转] NGUI自适应
  19. Docx4j将html转成word时,br标签为软回车的问题修改
  20. Eclipse下maven部署web项目到tomcat7(兼容tomcat8)

热门文章

  1. python logging 模块的应用
  2. LAMP搭建个人网站
  3. EmBitz1.11中将左边的目录弄出来
  4. 基于Hexo+Node.js+github+coding搭建个人博客——基础篇
  5. UGUI中Event Trigger的基本用法
  6. xdoj--1144 (合并模板)--有趣的优先队列(优先队列默认权值最大的数在前面)
  7. fast ai环境配置
  8. loadrunner如何对mysql进行增删改查
  9. 基础练习 2n皇后问题
  10. Go Example--方法