TabControl TabPage添加关闭按钮
自定义控件代码如下:
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 + " ";
}
运行效果如下:

TabControl TabPage添加关闭按钮的更多相关文章
- C# 重绘tabControl,添加关闭按钮(页签)
C# 重绘tabControl,添加关闭按钮(页签) 调用方法 参数: /// <summary> /// 初始化 /// </summary> /// <param n ...
- C# 重绘tabControl,添加关闭按钮(续)
在上一篇随笔中,添加关闭按钮是可以实现 ,但细心一点就会发现,每次关闭一个选项卡,tableControl都会自动跳到第一个页面,显然 这不是我们想要的,为此,我修改了部分的代码.除此之外,我还添加了 ...
- 向tabcontrol中添加form
昨天花了一天的时间去找一个错误,关系是这样的,我添加一个tabcontrol就叫tc1好了,然后在tc1中再动态添加一个父窗体l叫form1,要把form1添加进tabcontrol就要先新建一个ta ...
- TabControl里面添加From
private void dynamicDll() { string dllName = "dll"; Assembly ass = Assembly.Load(dllName); ...
- TabControl重写,添加关闭按钮
class userTabControl : TabControl { const int CLOSE_SIZE = 15; protected override void OnInvalidated ...
- Tabcontrol动态添加TabPage(获取或设置当前选项卡及其属性)
http://blog.csdn.net/xiongxyt2/article/details/6920575 •MultiLine 属性用true 或false来确定是否可以多行显示 •Appeara ...
- 转: 向tabControl中添加一个Form(C#)
- C# Winform TabControl 双击关闭TabPage
在使用TabControl控件时,需要考虑自动创建的TabPage页实现——关闭功能 思路一:自定义TabControl控件,添加关闭按钮 思路二:TabControl控件TabPage显示ToolT ...
- C# winform 中 TabControl 动态显示 TabPage
在winform应用中,tabcontrol是一个很好的控件,可以根据需求提供多个选项卡(TabPages),但是有一个问题是当某个项目需要多个选项卡,但是不同的功能要求显示不同的选项卡,其他的非该功 ...
随机推荐
- 【leetcode】350. Intersection of Two Arrays II
problem 350. Intersection of Two Arrays II 不是特别明白这道题的意思,例子不够说明问题: 是按顺序把相同的元素保存下来,还是排序,但是第二个例子没有重复... ...
- Python之路,第二十篇:Python入门与基础20
python3 面向对象4 supper 函数 supper(type, obj) 返回绑定超类的实例(要求obj必须为type类型的实例) supper() 返回绑定的超类的实例,等同于(cl ...
- Pytorch基本变量类型FloatTensor与Variable
pytorch中基本的变量类型当属FloatTensor(以下都用floattensor),而Variable(以下都用variable)是floattensor的封装,除了包含floattensor ...
- vim 删除
shift + $ :光标往后 shift + ^ :光标往前 shift + D 删除当前光标直到末尾
- ECUST Div2 训练赛3 (只有代码)
题解见:http://ecustacm.cn/contest/11/announcements A #include<bits/stdc++.h> #define rep(i,a,b) f ...
- python学习之路02
1.python的数据类型有:Number String List Truple Sets Dictionary . 数字类型:int float bool complex 2.不可变数据:数字 字符 ...
- grep 的学习 正则
grep 命令: grep "name" /path/file_name 从file_name文件中中查找 name 字符 grep -c "name ...
- Manjaro启动项目及服务配置备忘
Manjaro启动项目及服务配置备忘 =============== 系统服务GUI管理搜索 systemdgenie 并安装,类似Windows的服务管理. ================ 系统启 ...
- XML映射配置文件
XML映射配置文件 http://www.mybatis.org/mybatis-3/configuration.html Type Handlers 类型处理器 每当MyBatis在Prepared ...
- (2)MySQL的增删改查基本操作
数据库增删改查的基本操作(数据文件在data目录下) 数据库的专业术语 1.文件夹:数据库 2.文件:数据表 指令的注意事项 1.用use的时候指令结尾不需要跟一个分号 ‘:’ 2.如果用show或其 ...