文件下载: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. 【HDOJ】4089 Activation

    1. 题目描述长度为n的等待队列,tomato处于第m个,有如下四种可能:(1)激活失败,概率为$p_1$,队列中的顺序不变:(2)连接失败,概率为$p_2$,队头玩家重新排在队尾:(3)激活成功,概 ...

  2. 编写高效的C程序与C代码优化

    本文地址:http://www.cnblogs.com/archimedes/p/writing-efficient-c-and-code-optimization.html,转载请注明源地址. 说明 ...

  3. innodb b+树

    http://www.admin10000.com/document/5372.html

  4. 记一次SSH登陆失败问题的定位

    创建用户之后,使用ssh协议登陆提示失败. useradd -d /home/hdp -m hdp -g dba -s /bin/bash 通过命令 ssh -v hdp@127.0.0.1 登陆,查 ...

  5. Unity3d插件推荐

    2D_Toolkit_1.51 动画开发插件包 FingerGestures 触摸插件 ORK_Okashi_RPG_Kit Unity3D角色扮演游戏开发工具包 uScript-Visual-Scr ...

  6. ☀【document / location】

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...

  7. c语言宏定义#define的理解与资料整理

    1. 利用define来定义 数值宏常量 #define 宏定义是个演技非常高超的替身演员,但也会经常耍大牌的,所以我们用它要慎之又慎.它可以出现在代码的任何地方,从本行宏定义开始,以后的代码就就都认 ...

  8. Java多态中的注意事项

    1.“覆盖”私有方法 public class PrivateOverride { private void f() { print("private f()"); } publi ...

  9. oracle导入到Excel

    一.从oracle到处数据到excel文件方法一.直接从PL/SQL中,全选数据,然后复制粘贴到excel中: 方法二.同样是通过PL/SQL,在数据列中,点击右键-->导出结果-->选择 ...

  10. ZEat

    借助微博平台,记录每日饮食情况的Andorid程序. 项目地址:https://github.com/atskyline/ZEat 1.0.0APK下载地址:https://github.com/at ...