文件下载:http://files.cnblogs.com/zfanlong1314/TabControlEX.rar

本文转载:http://www.cnblogs.com/lmlblog/archive/2012/03/29/TabControl.html

最近因项目需要 所以就到网上找了一个美化过的TabControl控件   只不过这个控件没有实现TabPage的关闭功能 所以就自己添加了一个关闭功能

好了废话不多说

直接贴代码

UpDownButtonPaintEventArgs 类的代码

 1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Windows.Forms;
5 using System.Drawing;
6
7 namespace StyleWinForm.TabControls
8 {
9 public delegate void UpDownButtonPaintEventHandler(
10 object sender,
11 UpDownButtonPaintEventArgs e);
12
13 public class UpDownButtonPaintEventArgs : PaintEventArgs
14 {
15 private bool _mouseOver;
16 private bool _mousePress;
17 private bool _mouseInUpButton;
18
19 public UpDownButtonPaintEventArgs(
20 Graphics graphics,
21 Rectangle clipRect,
22 bool mouseOver,
23 bool mousePress,
24 bool mouseInUpButton)
25 : base(graphics, clipRect)
26 {
27 _mouseOver = mouseOver;
28 _mousePress = mousePress;
29 _mouseInUpButton = mouseInUpButton;
30 }
31
32 public bool MouseOver
33 {
34 get { return _mouseOver; }
35 }
36
37 public bool MousePress
38 {
39 get { return _mousePress; }
40 }
41
42 public bool MouseInUpButton
43 {
44 get { return _mouseInUpButton; }
45 }
46 }
47 }

NativeMethods 类的代码

 1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Runtime.InteropServices;
5 using System.Drawing;
6
7 namespace StyleWinForm.TabControls
8 {
9 internal class NativeMethods
10 {
11 public const int WM_PAINT = 0xF;
12
13 public const int VK_LBUTTON = 0x1;
14 public const int VK_RBUTTON = 0x2;
15
16 private const int TCM_FIRST = 0x1300;
17 public const int TCM_GETITEMRECT = (TCM_FIRST + 10);
18
19 public static readonly IntPtr TRUE = new IntPtr(1);
20
21 [StructLayout(LayoutKind.Sequential)]
22 public struct PAINTSTRUCT
23 {
24 internal IntPtr hdc;
25 internal int fErase;
26 internal RECT rcPaint;
27 internal int fRestore;
28 internal int fIncUpdate;
29 internal int Reserved1;
30 internal int Reserved2;
31 internal int Reserved3;
32 internal int Reserved4;
33 internal int Reserved5;
34 internal int Reserved6;
35 internal int Reserved7;
36 internal int Reserved8;
37 }
38
39 [StructLayout(LayoutKind.Sequential)]
40 public struct RECT
41 {
42 internal RECT(int X, int Y, int Width, int Height)
43 {
44 this.Left = X;
45 this.Top = Y;
46 this.Right = Width;
47 this.Bottom = Height;
48 }
49 internal int Left;
50 internal int Top;
51 internal int Right;
52 internal int Bottom;
53 }
54
55 [DllImport("user32.dll")]
56 public static extern IntPtr FindWindowEx(
57 IntPtr hwndParent,
58 IntPtr hwndChildAfter,
59 string lpszClass,
60 string lpszWindow);
61
62 [DllImport("user32.dll")]
63 public static extern IntPtr BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
64
65 [DllImport("user32.dll")]
66 [return: MarshalAs(UnmanagedType.Bool)]
67 public static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
68
69 [DllImport("user32.dll")]
70 public static extern short GetKeyState(int nVirtKey);
71
72 [DllImport("user32.dll")]
73 public static extern IntPtr SendMessage(
74 IntPtr hWnd, int Msg, int wParam, ref RECT lParam);
75
76 [DllImport("user32.dll")]
77 [return: MarshalAs(UnmanagedType.Bool)]
78 public static extern bool GetCursorPos(ref Point lpPoint);
79
80 [DllImport("user32.dll")]
81 public extern static int OffsetRect(ref RECT lpRect, int x, int y);
82
83 [DllImport("user32.dll")]
84 [return: MarshalAs(UnmanagedType.Bool)]
85 public static extern bool PtInRect([In] ref RECT lprc, Point pt);
86
87 [DllImport("user32.dll")]
88 [return: MarshalAs(UnmanagedType.Bool)]
89 public static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
90
91 [DllImport("user32.dll")]
92 [return: MarshalAs(UnmanagedType.Bool)]
93 public static extern bool GetClientRect(IntPtr hWnd, ref RECT r);
94
95 [DllImport("User32.dll", CharSet = CharSet.Auto)]
96 public static extern bool IsWindowVisible(IntPtr hwnd);
97 }
98 }

TabControl组件的代码

  

 1  #region 为TabControl添加关闭按钮
2 const int CLOSE_SIZE = 15;
3 //关闭按钮功能
4 private void MainTabControl_MouseDown(object sender, MouseEventArgs e)
5 {
6 if (tabContent.SelectedTab.Name != "tabPageWelcome")
7 {
8 if (e.Button == MouseButtons.Left)
9 {
10 int x = e.X, y = e.Y;
11 //计算关闭区域
12 Rectangle myTabRect = this.tabContent.GetTabRect(this.tabContent.SelectedIndex);
13
14 myTabRect.Offset(myTabRect.Width - (CLOSE_SIZE + 3), 2);
15 myTabRect.Width = CLOSE_SIZE;
16 myTabRect.Height = CLOSE_SIZE;
17
18 //如果鼠标在区域内就关闭选项卡
19 bool isClose = x > myTabRect.X && x < myTabRect.Right && y > myTabRect.Y && y < myTabRect.Bottom;
20 if (isClose == true)
21 {
22 this.tabContent.TabPages.Remove(this.tabContent.SelectedTab);
23 }
24 }
25 }
26 }
27 #endregion

TabControl控件的美化的更多相关文章

  1. WPF之TabControl控件用法

    先创建实体基类:NotificationObject(用来被实体类继承) 实现属性更改通知接口: using System; using System.Collections.Generic; usi ...

  2. Visual Studio中的TabControl控件的用法

    今天遇到了一个自己没遇到过的控件TabControl控件,所以找了点关于它的资料 TabControl属性 DisplayRect:只定该控件客户区的一个矩形  HotTrack:设置当鼠标经过页标签 ...

  3. WPF 自定义TabControl控件样式

    一.前言 程序中经常会用到TabControl控件,默认的控件样式很普通.而且样式或功能不一定符合我们的要求.比如:我们需要TabControl的标题能够居中.或平均分布:或者我们希望TabContr ...

  4. C#利用tabControl控件实现多窗体嵌入及关闭

    创建一个主窗体(Formmain).两个副窗体(Form1,Form2);在主窗体中分别添加一个menuStrip控件.tabControl控件,并在menu控件上添加一个主菜单和两个子菜单   继而 ...

  5. WinForm下的TabControl控件

    一.TabControl控件介绍 TabControl实现的具体效果: 在实际工作中,我是这么用TabControl控件,实现切换页面效果.比如要实现某个界面进行操作,然后还要查看一下日志,就可以使用 ...

  6. WPF TabControl控件-事件相关问题

    TabControl控件的TabItem的Content元素,例如:DataGrid控件,在对事件的处理时,需要对事件的源引起关注,当需要处理DataGrid的事件时,事件会传递到TabControl ...

  7. 隐藏C#的TabControl控件的选项卡TabPage

    在使用TabControl控件时,希望隐藏其中某个选项卡(即TabPage).TabPage类明明提供了一个Hide方法,用在代码中却没有任何效果,甚是奇怪.无奈之余,只好考虑另辟途径.方法一:设置该 ...

  8. TabControl控件和TabPage

    TabControl控件和TabPageTabControl控件可以支持在一个控件里面放置多个选项卡,每个选项卡又可以放置多个控件 由于在控件属性窗口添加选项卡相对比较容易,下面说一下动态创建选项卡 ...

  9. TabControl控件用法图解

    1.首先创建一个MFC对话框框架,在对话框资源上从工具箱中添加上一个TabControl控件 2.根据需要修改一下属性,然后右击控件,为这个控件添加一个变量,将此控件跟一个CTabCtrl类变量绑定在 ...

随机推荐

  1. hdu4635Strongly connected

    http://acm.hdu.edu.cn/showproblem.php?pid=4635 tarjan缩点 统计缩点后每个结点的出度入度 将那个包含原来点数最少的 且出度或者入度为0的大节点看作一 ...

  2. Codeforces Round #224 (Div. 2)

    题目:http://codeforces.com/contest/382 A Ksenia and Pan Scales 一个求天平是否能够平衡的题目...水题,注意一下结果的输出就行. #inclu ...

  3. createSQLQuery与createQuery的区别

    本文原址 : http://stta04.javaeye.com/blog/377633hibernate 中createQuery与createSQLQuery 昨晚帮同事看代码到凌晨2点多,今早6 ...

  4. poj3225 线段树区间操作 (见鬼)

    细节处理实在太重要了. #include<cstdio> #include<cstring> #define MT 65533*4 #define Maxn MT*4 int ...

  5. 嵌入式linux市场份额

    来自华清远见2014年度的调查统计数据显示,在嵌入式产品研发的软件开发平台的选择上,嵌入式Linux以55%的市场份额遥遥领先于其他嵌入式开发软件发平台,比去年增长了13个百分比,这已经是连续4年比例 ...

  6. 装饰器模式(Decorator)

    转自http://blog.csdn.net/hust_is_lcd/article/details/7884320 1.认识装饰器模式 装饰模式能够实现动态的为对象添加功能,是从一个对象外部来给对象 ...

  7. 【转】 当程序崩溃的时候怎么办 part-1

    转自:http://www.tairan.com/archives/1006 有这样一种情形:当我们正在快乐的致力于我们的app时,并且什么看都是无比顺利,但是突然,坑爹啊,它崩溃了.(悲伤地音乐响起 ...

  8. 学习Erlang--1、入门

    1.正式起航 从前,一名程序员偶然读到了一本古怪的语言图书,相等其实不是相等,变量其实是不能改变的,语法是那么陌生,它甚至不是面向对象,这些程序实在是太过另类…… 另类的不仅仅是程序,编程的教学步骤也 ...

  9. 使用SQL Server 2005作业设置定时任务

    公司有一个老项目由于直接把终端拍摄的图片以二进制的形式保存到数据库中,数据库比较大所以需要经常删除这些冗余数据,手动删除费时费力,项目组长让我把这些操作变成自动的,每天执行一次,只保留最近两个月的图片 ...

  10. ollydbg z

    通达信l2密码器方法: 1:使用Ollydbg,点文件,打开,选择通达信的可执行文件(或者把通达信的执行文件直接拖进Ollydbg的窗口),按F9运行程序. 2:正常使用通达信,进入到K线图后,在k线 ...