using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace KUN.CONTROL.LIB.KTabControl
{
public partial class KDelTabControl : TabControl
{
const int CLOSE_SIZE = 15;
//tabPage标签图片
Bitmap image = Properties.Resources.close; public KDelTabControl()
{
InitializeComponent(); this.DrawMode = TabDrawMode.OwnerDrawFixed;
//this.Padding = new System.Drawing.Point(CLOSE_SIZE, CLOSE_SIZE);
this.DrawItem += new DrawItemEventHandler(this.KDelTabControl_DrawItem);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.KDelTabControl_MouseDown);
} //绘制“X”号即关闭按钮
private void KDelTabControl_DrawItem(object sender, DrawItemEventArgs e)
{
try
{
Rectangle tab = this.GetTabRect(e.Index);
//先添加TabPage属性
e.Graphics.DrawString(this.TabPages[e.Index].Text, this.Font, SystemBrushes.ControlText, tab.X + 2, tab.Y + 2);
//再画一个矩形框
using (Pen p = new Pen(Color.White))
{
tab.Offset(tab.Width - (CLOSE_SIZE + 3), 2);
tab.Width = CLOSE_SIZE;
tab.Height = CLOSE_SIZE;
e.Graphics.DrawRectangle(p, tab);
}
//填充矩形框
Color recColor = e.State == DrawItemState.Selected ? Color.White : Color.White;
using (Brush b = new SolidBrush(recColor))
{
e.Graphics.FillRectangle(b, tab);
}
//画关闭符号
using (Pen objpen = new Pen(Color.Black))
{
////=============================================
//自己画X
////"\"线
//Point p1 = new Point(myTabRect.X + 3, myTabRect.Y + 3);
//Point p2 = new Point(myTabRect.X + myTabRect.Width - 3, myTabRect.Y + myTabRect.Height - 3);
//e.Graphics.DrawLine(objpen, p1, p2);
////"/"线
//Point p3 = new Point(myTabRect.X + 3, myTabRect.Y + myTabRect.Height - 3);
//Point p4 = new Point(myTabRect.X + myTabRect.Width - 3, myTabRect.Y + 3);
//e.Graphics.DrawLine(objpen, p3, p4); ////=============================================
//使用图片
Bitmap bt = new Bitmap(image);
Point p5 = new Point(tab.X, 4);
e.Graphics.DrawImage(bt, p5);
//e.Graphics.DrawString(this.MainTabControl.TabPages[e.Index].Text, this.Font, objpen.Brush, p5);
}
e.Graphics.Dispose();
}
catch (Exception)
{ }
} private void KDelTabControl_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
int x = e.X, y = e.Y;
//计算关闭区域
Rectangle tab = this.GetTabRect(this.SelectedIndex);
tab.Offset(tab.Width - (CLOSE_SIZE + 3), 2);
tab.Width = CLOSE_SIZE;
tab.Height = CLOSE_SIZE;
//如果鼠标在区域内就关闭选项卡
bool isClose = x > tab.X && x < tab.Right && y > tab.Y && y < tab.Bottom; if (isClose == true) this.TabPages.Remove(this.SelectedTab);
}
} }
}

  

C# TabControl 带删除的更多相关文章

  1. 35.Android之带删除按钮EditText学习

    今天实现Android里自定义带删除功能的EditText,效果如下: 当输入内容时,EditText变为带有一个删除功能按钮的编辑框,如图: 实现代码很简单,直接上代码, 布局文件xml: < ...

  2. Gridview中 LinkButton删除以及自带删除

    <asp:LinkButton ID="lbtnDel" OnClientClick="return confirm('删除新闻会连同其下评论一起删除,是否删除?' ...

  3. iOS_绘制带删除线的Label

    效果图例如以下: 一个带删除线的文本标签,继承自UILabel 自绘代码过程例如以下: 1,重写控件的drawRect方法 2,首先得到上下文对象 3,设置颜色,并指定是填充(Fill)模式还是笔刷( ...

  4. [Android]自己定义带删除输入框

    在项目开发中,带删除button输入框也是人们经常常使用到的,该文章便介绍一下怎样创建一个带删除输入框.当中,须要解决的问题例如以下: a)创建自己定义editText类 b)在自己定义editTex ...

  5. 【NOIP2017练习】怎样打好隔膜(贪心,堆,带删除priority_queue)

    题意:OI大师抖儿在夺得银牌之后,顺利保送pku.这一天,抖儿问长者:“我的手速虽然已经站在了人类的巅峰,但是打隔膜还是输.我换了很多队友,但是没有用.请问应该怎样打好隔膜?”长者回答:“你啊,Too ...

  6. 模拟邮箱输入邮箱地址、收藏标签。input框输入内容后回车,内容显示成小方块并带删除按钮。

    模拟邮箱输入邮箱地址.收藏标签: 文本框输入文字后按回车键或者分号键,输入框中的文字变成小块并带删除按钮和操作. 页面代码: <!DOCTYPE html> <%@ page lan ...

  7. Codeforces 948 数论推导 融雪前缀和二分check 01字典树带删除

    A. 全部空的放狗 B. 先O(NLOGNLOGN)处理出一个合数质因数中最大的质数是多少 因为p1 x1 x2的关系是 x2是p在x1之上的最小倍数 所以x1的范围是[x2-p+1,x2-1]要使最 ...

  8. 带删除小图标的EditText

    import android.content.Context; import android.graphics.Rect; import android.graphics.drawable.Drawa ...

  9. 带删除的EditText

    在安卓开发中EditText是比较常用的控件之一,那我们平常看到EditText填写了内容之后右边会出现一个删除的按钮,这样可以方便用户对其中文本清空操作,是非常人性化的,我们可以重写EditText ...

随机推荐

  1. 【python画图】

    1.热力图 import numpy as np import numpy.random import matplotlib.pyplot as plt # Generate some test da ...

  2. Docker-compose容易忽略的使用细节

    Docker-compose是docker官方的开源项目,通过使用模版yaml文件,实现对docker容器集群的管理.具体教程可以通过官方地址进行实践.Docker-compose主要有两个重要的概念 ...

  3. 【VS开发】C/C++预编译命令

    C/C++中宏总结C程序的源代码中可包括各种编译指令,这些指令称为预处理命令或预处理器.虽然它们实际上不是C语言的一部分,但却扩展了C程 序设计的环境. 预处理指令的主要作用就是把通过预处理的内建功能 ...

  4. 日志.VC

    1. int WriteLog(char* _pcFullFileName, char* _pcWrite, int _iWriteLen, unsigned long * _pdwWritten) ...

  5. redis 获取方式和安装(windows)

    Windows redis :https://github.com/MSOpenTech/redis/releases Linux redis :https://github.com/phpredis ...

  6. 如何编写spring mvc 项目

    src/main/resources/static 目录里放资源文件css js jpg src/main/resources/templates 目录里放模板,html模板/这里是内容的展示页面 s ...

  7. #【Python】【demo实验23】【练习实例】【 三人比赛顺序问题 】

    原题: 两个乒乓球队进行比赛,各出三人.甲队为a,b,c三人,乙队为x,y,z三人.已抽签决定比赛名单.有人向队员打听比赛的名单.a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单. 我的 ...

  8. centos 安装go

    [root@golong-learning src]# wget https://dl.google.com/go/go1.12.7.linux-amd64.tar.gz # 下载 [root@gol ...

  9. mybatis缓存机制与装饰者模式

    mybatis 缓存 MyBatis的二级缓存的设计原理 装饰者模式

  10. 【LOJ】#3101. 「JSOI2019」精准预测

    LOJ#3101. 「JSOI2019」精准预测 设0是生,1是死,按2-sat连边那么第一种情况是\((t,x,1) \rightarrow (t + 1,y,1)\),\((t + 1,y, 0) ...