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. unity3d 触屏多点触控(旋转与缩放)

    unity3d 触屏多点触控(旋转与缩放) /*Touch OrbitProgrammed by: Randal J. Phillips (Caliber Mengsk)Original Creati ...

  2. UE4 RHI与条件式编译

    RHI即RenderHardwareInterface, 即渲染硬件接口, 是UE为实现跨平台而实现的一套API. 每个RHI接口都为OpenGL, Vulkan, DX11等做了不同的实现. 在引擎 ...

  3. pytest.mark.parametrize()参数化应用二,读取json文件

    class TestEnorll(): def get_data(self): """ 读取json文件 :return: """ data ...

  4. 【Matlab开发】matlab中bar绘图设置与各种距离度量

    [Matlab开发]matlab中bar绘图设置与各种距离度量 标签(空格分隔): [Matlab开发] [机器学习] 声明:引用请注明出处http://blog.csdn.net/lg1259156 ...

  5. 【DSP开发】硬件信号量在多核处理器核间通信中的应用

    硬件信号量在多核处理器核间通信中的应用 刘德保1,汪安民1,韩道文2 1.同方电子科技有限公司研究所,九江 332009:2.解放军电子工程学院 摘要: 在多核处理器的软件设计中,核间通信机制是关键所 ...

  6. Odoo13 新变化:会计

    Odoo13将于2019年10月发布,本次发布也包含了大量的改进,例如,对会计的重构. 去掉了 account.invoice / account.invoice.line/ account.vouc ...

  7. Reactor系列(五)map映射

    #java# #reactor# #flux# #map# #映射# 视频解视: https://www.bilibili.com/video/av79179444/ FluxMonoTestCase ...

  8. EMR-LDAP配置

    usersync是负责在配置policy的时候可选用户有ldap里的用户,admin是负责登录webui的 https://cwiki.apache.org/confluence/display/RA ...

  9. 正式发布! .NET开发控件集ComponentOne 新版本加入Blazor UI

    近期,由葡萄城推出的ComponentOne .NET开发控件集正式发布最新版本! ComponentOne 是一套专注于企业 .NET开发.支持 .NET Core 平台,并完美集成于 Visual ...

  10. 【LOJ】#3051. 「十二省联考 2019」皮配

    LOJ#3051. 「十二省联考 2019」皮配 当时我在考场上觉得这题很不可做... 当然,出了考场后再做,我还是没发现学校和城市是可以分开的,导致我还是不会 事实上,若一个城市投靠了某个阵营,学校 ...