C# 重绘tabControl,添加关闭按钮(页签)
C# 重绘tabControl,添加关闭按钮(页签)
调用方法
参数:
/// <summary>
/// 初始化
/// </summary>
/// <param name="tabcontrol">TacControl控件</param>
/// <param name="fo">主程序this.Font</param> DrawTabControl dtc=new DrawTabControl(tabControl1,this.Font);
dtc.ClearPage();
类
#region 重绘tablecontrol
public class DrawTabControl
{
TabControl tabControl1 = null;
Font font1 = null;
public DrawTabControl() { }
public DrawTabControl(TabControl tabcontrol,Font fo)
{
tabControl1 = tabcontrol;
font1 = fo;
} const int CLOSE_SIZE = ;
//tabPage标签图片
Bitmap image = new Bitmap("D:\\power_003.png"); public void ClearPage()
{ //清空控件
//this.MainTabControl.TabPages.Clear();
//绘制的方式OwnerDrawFixed表示由窗体绘制大小也一样
this.tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
this.tabControl1.Padding = new System.Drawing.Point(CLOSE_SIZE, CLOSE_SIZE - );
this.tabControl1.DrawItem += new DrawItemEventHandler(this.tabControl1_DrawItem);
this.tabControl1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tabControl1_MouseDown);
} private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
try
{
Rectangle myTabRect = this.tabControl1.GetTabRect(e.Index); //先添加TabPage属性
e.Graphics.DrawString(this.tabControl1.TabPages[e.Index].Text, this.font1, SystemBrushes.ControlText, myTabRect.X + , myTabRect.Y + ); //再画一个矩形框
using (Pen p = new Pen(Color.White))
{
myTabRect.Offset(myTabRect.Width - (CLOSE_SIZE + ), );
myTabRect.Width = CLOSE_SIZE;
myTabRect.Height = CLOSE_SIZE;
e.Graphics.DrawRectangle(p, myTabRect);
} //填充矩形框
Color recColor = e.State == DrawItemState.Selected ? Color.White : Color.White;
using (Brush b = new SolidBrush(recColor))
{
e.Graphics.FillRectangle(b, myTabRect);
} //画关闭符号
using (Pen objpen = new Pen(Color.Black))
{
////=============================================
//自己画X
////"\"线
Point p1 = new Point(myTabRect.X + , myTabRect.Y + );
Point p2 = new Point(myTabRect.X + myTabRect.Width - , myTabRect.Y + myTabRect.Height - );
e.Graphics.DrawLine(objpen, p1, p2);
////"/"线
Point p3 = new Point(myTabRect.X + , myTabRect.Y + myTabRect.Height - );
Point p4 = new Point(myTabRect.X + myTabRect.Width - , myTabRect.Y + );
e.Graphics.DrawLine(objpen, p3, p4); ////=============================================
//使用图片
//Bitmap bt = new Bitmap(image);
//Point p5 = new Point(myTabRect.X, 4);
//e.Graphics.DrawImage(bt, p5);
//e.Graphics.DrawString(this.MainTabControl.TabPages[e.Index].Text, this.font1, objpen.Brush, p5);
}
e.Graphics.Dispose();
}
catch (Exception)
{ }
} private void tabControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
int x = e.X, y = e.Y;
//计算关闭区域
Rectangle myTabRect = this.tabControl1.GetTabRect(this.tabControl1.SelectedIndex); myTabRect.Offset(myTabRect.Width - (CLOSE_SIZE + ), );
myTabRect.Width = CLOSE_SIZE;
myTabRect.Height = CLOSE_SIZE; //如果鼠标在区域内就关闭选项卡
bool isClose = x > myTabRect.X && x < myTabRect.Right && y > myTabRect.Y && y < myTabRect.Bottom;
if (isClose == true)
{
this.tabControl1.TabPages.Remove(this.tabControl1.SelectedTab);
}
}
} }
#endregion
C# 重绘tabControl,添加关闭按钮(页签)的更多相关文章
- C#重绘TabControl
C#重绘TabControl的Tabpage标签,添加图片及关闭按钮 Code highlighting produced by Actipro CodeHighlighter (freeware)h ...
- C# 重绘tabControl,添加关闭按钮(续)
在上一篇随笔中,添加关闭按钮是可以实现 ,但细心一点就会发现,每次关闭一个选项卡,tableControl都会自动跳到第一个页面,显然 这不是我们想要的,为此,我修改了部分的代码.除此之外,我还添加了 ...
- WinForm中重绘TabControl选项卡标题
最近开发WinForm频繁使用了TabControl控件,这个控件的选项卡没有BackgroundImage这个属性,那么如何为其各个选项卡添加背景图片呢?(这里说的是每个TabPage的头部,也就是 ...
- 重绘TabControl
本文转载自:http://blog.csdn.net/conmajia/article/details/7596718 作者:野比 (conmajia@gmail.com) 时间:May, 2012 ...
- C# 自定义重绘TabControl
using System.Drawing; using System.Windows.Forms; using System.Drawing.Drawing2D; using System.Runti ...
- [转] JQuery UI Tabs 动态添加页签,并跳转到新页签
[From] https://blog.csdn.net/zhangfeng2124/article/details/76672403 需求: 1.tabs默认只有一个页签,但是需要点击某按钮,动态添 ...
- TabControl控件重绘
原文地址:http://www.codeproject.com/Articles/91387/Painting-Your-Own-Tabs-Second-Edition 在网上看到重绘TabContr ...
- C#实现Excel操作——添加页签Sheet
C#实现对Excel操作,根据数据的类型不同或者来源不同会放在不同的页签中,C#实现添加页签代码如下:(path为文档保存的地址,dt为要处理的源数据) public void addSheet(st ...
- Windows开发进阶之VC++中如何实现对话框的界面重绘
技术:Windows 系统+Visual studio 2008 概述 应用程序界面是用户与应用程序之间的交互的桥梁和媒介,用户界面是应用程序中最重要的组成部分,也是最为直观的视觉体现.对用户而言 ...
随机推荐
- Ubuntu 16.04播放器Rhythmbox乱码解决
使用Rhythmbox进行音乐播放的时候,歌曲名称专辑歌手名称都出现乱码,查看了网上很多教程,要不就是将音频转码,要不就是修改用户环境编码配置.前一种方法对音频有改动,后一种可能无效还有可能会影响系统 ...
- PHP socket编程需要了解的一些基本知识
前面讲到了 fsockopen 的各种情况,其中涉及了很多其它知识,比如chunked分段传输,Keep-Alive,HTTP头字段等额外的知识,如果对这些知识一知半解,会影响对 PHP 的 sock ...
- linux下的shell运算(加、减、乘、除)
linux下的shell运算(加.减.乘.除) 标签: linuxshell运算加减乘除 2014-03-12 16:25 15127人阅读 评论(0) 收藏 举报 分类: linux(17) ((i ...
- centos 7 升级后yum install出现Exiting on user cancel
centos 7 升级后yum install出现Exiting on user cancel centos 7.x升级后用yum install进行安装时经常出现Exiting on user ca ...
- android studio Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
android studio Error:java.lang.OutOfMemoryError: GC overhead limit exceeded 在app下的build.gradle中找到and ...
- vs2013 控制台程序exe图标
工程右击选择添加resource->Icon. 在工程目录就会生成 工程名.rc 和 XX.ico文件. 重新编译程序,就会生成有图标的exe. 对应的配置在 工程名.rc 文件里,用记事 ...
- ffmpeg-20160811-bin.7z
ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...
- iOS基础框架的搭建/国际化操作
1.基础框架的搭建 1.1 pod引入常用的第三方类库 1.2 创建基础文件夹结构/目录结构 Resource———存放声音/图片/xib/storyboard 等资源文件 Define——宏定义, ...
- Effective C++ -----条款32:确定你的public继承塑模出is-a关系
“public继承”意味is-a.适用于base classes身上的每一件事情一定也适用于derived classes身上,因为每一个derive class对象也都是一个base class对象 ...
- nyoj138 找球号(二)_离散化
找球号(二) 时间限制:1000 ms | 内存限制:65535 KB 难度:5 描述 在某一国度里流行着一种游戏.游戏规则为:现有一堆球中,每个球上都有一个整数编号i(0<=i< ...