【Winform-自定义控件】自定义Tab Control 带关闭符号(X)的标签页
a form & a tabControl
思路:
DrawMode设一定要设为OwnerDrawFixed
事件:Form_Load、tabControl1_DrawItem、tabControl1_DrawItem
注意:
如果 设置tabControl的SizeMode为fixed,则标签页的长度以最大的为标准
如果 设置tabControl的SizeMode为normal,则标签页的长度随标题变化,
此句代码:tabControl1.Padding = new System.Drawing.Point(21, 3); 表示‘X’与标题间有空隙。
namespace Demo
{
public partial class Form7 : Form
{
const int LEADING_SPACE = ;
const int CLOSE_SPACE = ;
const int CLOSE_AREA = ; public Form7()
{
InitializeComponent();
this.tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
} private void Form7_Load(object sender, EventArgs e)
{
// get the inital length
int tabLength = tabControl1.ItemSize.Width; // measure the text in each tab and make adjustment to the size
for (int i = ; i < this.tabControl1.TabPages.Count; i++)
{
TabPage currentPage = tabControl1.TabPages[i]; int currentTabLength = TextRenderer.MeasureText(currentPage.Text, tabControl1.Font).Width;
// adjust the length for what text is written
currentTabLength += LEADING_SPACE + CLOSE_SPACE + CLOSE_AREA; if (currentTabLength > tabLength)
{
tabLength = currentTabLength;
}
} // create the new size
Size newTabSize = new Size(tabLength, tabControl1.ItemSize.Height);
tabControl1.ItemSize = newTabSize;
} private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
//add some extra space to the end of every tabPage
tabControl1.Padding = new System.Drawing.Point(, ); //render a "x" mark at the end of the Tab caption
e.Graphics.DrawString("x", e.Font, Brushes.Black, e.Bounds.Right - CLOSE_AREA, e.Bounds.Top + );
e.Graphics.DrawString(this.tabControl1.TabPages[e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left + LEADING_SPACE, e.Bounds.Top + );
e.DrawFocusRectangle();
} private void tabControl1_MouseDown(object sender, MouseEventArgs e)
{
//Looping through the controls.
for (int i = ; i < this.tabControl1.TabPages.Count; i++)
{
Rectangle r = tabControl1.GetTabRect(i);
//Getting the position of the "x" mark.
Rectangle closeButton = new Rectangle(r.Right - , r.Top + , , );
if (closeButton.Contains(e.Location))
{
if (MessageBox.Show("Would you like to Close this Tab?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
this.tabControl1.TabPages.RemoveAt(i);
break;
}
}
}
}
}
}
【Winform-自定义控件】自定义Tab Control 带关闭符号(X)的标签页的更多相关文章
- (八十九)c#Winform自定义控件-自定义滚动条(treeview、panel、datagridview、listbox、listview、textbox)
官网 http://www.hzhcontrols.com/ 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kw ...
- 创建带标签页的MDI WinForms应用程序
http://www.cnblogs.com/island/archive/2008/12/02/mditab.html 创建MDI应用程序 先创建”Windows窗体应用程序”解决方案Tabable ...
- 标签页(tab)切换的原生js,jquery和bootstrap实现
概述 这是我在学习课程Tab选项卡切换效果时做的总结和练手. 原课程中只有原生js实现,jquery和bootstrap实现是我自己补上的. 本节内容 标签页(tab)切换的原生js实现 标签页(ta ...
- Bootstrap 标签页(Tab)插件
摘自: http://www.runoob.com/bootstrap/bootstrap-tab-plugin.html Bootstrap 标签页(Tab)插件 标签页(Tab)在 Bootstr ...
- Bootstrap-Plugin:标签页(Tab)插件
ylbtech-Bootstrap-Plugin:标签页(Tab)插件 1.返回顶部 1. Bootstrap 标签页(Tab)插件 标签页(Tab)在 Bootstrap 导航元素 一章中介绍过.通 ...
- Bootstrap标签页(Tab)插件事件
事件 下表列出了标签页(Tab)插件中要用到的事件.这些事件可在函数中当钩子使用. 事件 描述 实例 show.bs.tab 该事件在标签页显示时触发,但是必须在新标签页被显示之前.分别使用 even ...
- (三十)c#Winform自定义控件-文本框(三)
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- Winform自定义控件实例
本文转自http://www.cnblogs.com/hahacjh/archive/2010/04/29/1724125.html 写在前面: .Net已经成为许多软件公司的选择,而.Net自定义W ...
- (三十一)c#Winform自定义控件-文本框(四)
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
随机推荐
- redis哨兵sentinel.conf文件
关闭保护模式 //17行 protected-mode no 端口号 //21 port 26379 后台启动 //26 daemonize yes //84行 主机的ip加端口号 2 为票数 sen ...
- linux下selenium+phantomjs环境
# 安装依赖软件yum -y install wget fontconfig # 下载PhantomJSwget -P /tmp/ https://bitbucket.org/ariya/phanto ...
- 植物大战僵尸:寻找阳光掉落Call调用
实验目标:通过遍历阳光产生的时间,寻找阳光产生的本地Call,使用代码注入器注入,自定义生成阳光 阳光CALL遍历技巧: 进入植物大战僵尸-> 当出现阳光后->马上搜索未知初始数值 返回游 ...
- luogu P2765 魔术球问题 (最小路径覆盖)
大意:给定n根柱子, 依次放入1,2,3,...的球, 同一根柱子相邻两个球和为完全平方数, 求最多放多少个球. 对和为平方数的点连边, 就相当于求DAG上最小路径覆盖. #include <i ...
- docker推送镜像到docker本地仓库报错:http: server gave HTTP response to HTTPS client
因为Docker从1.3.X之后,与docker registry交互默认使用的是https,然而此处搭建的私有仓库只提供http服务,所以当与私有仓库交互时就会报上面的错误. 解决办法: vim / ...
- CSS 小工具集
http://www.colorzilla.com/gradient-editor/css渐变生成工具.http://linxz.github.io/tianyizone/css志爷小工具.http: ...
- (๑•̀ㅂ•́)و✧QQ用户信息管理系统
这是第二篇文章,就直接切主题 这次剖析的也是自己的作业之一:QQ信息管理系统 一:(此处省略了建Proarams类,其实目的只是想强调把连接语句单独放一个类里更容易调用,命名规范如图) 二:(导入SQ ...
- 数据集:Introduction to Econometrics by Stock&Watson
James H. Stock and Mark W. Watson, Introduction to Econometrics: data sets 詹姆斯·H·斯托克 马克·W·沃森. 计量经济学. ...
- SQL*Loader 的使用sqlldr和sqluldr2方法详解
oracle数据导出工具sqluldr2可以将数据以csv.txt等格式导出,适用于大批量数据的导出,导出速度非常快.导出后可以使用oracle loader工具将数据导入.简介:Sqluldr2:专 ...
- 第十五章、线程之queue模块的各种队列
目录 第十五章.线程之queue模块的各种队列 一.Queue 二.LifoQueue堆栈 三.PriorityQueue优先级队列 第十五章.线程之queue模块的各种队列 一.Queue impo ...