TabControl控件的美化

文件下载: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 : PaintEventArgs14     {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 MouseOver33         {34             get { return _mouseOver; }35         }36 37         public bool MousePress38         {39             get { return _mousePress; }40         }41 42         public bool MouseInUpButton43         {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 NativeMethods10     {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 PAINTSTRUCT23         {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 RECT41         {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组件的代码

 

+ View Code

  

 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

 

时间: 2024-08-04 03:31:17

TabControl控件的美化的相关文章

System.Windows.Forms.TabControl控件的示例

发现学生们特别喜欢用TabControl控件,问过之后才知道,原来他们觉得这个控件看上去比较酷,难怪现在标签式浏览器这么受欢迎.既然喜欢,咱就投其所好,赶紧做了一点教学示例. 这里演示了TabControl的常用事件:SelectedIndexChanged Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.Sel

tabcontrol 添加页-关于TabControl控件的使用

问题描述 关于TabControl控件的使用 请问各位大神们,如何实现:在一个窗体中,点击一个按钮"添加一页",实现Tabcontrol中添加一个TabPage,但是添加时TabPage中要能拥有一些控件,如ListView,Button等.请问如何实现啊?

vs2008 C# 在tabControl控件、选项卡、虚拟画布、重绘、最小化、切换选项卡

问题描述 vs2008 C# 在tabControl控件.选项卡.虚拟画布.重绘.最小化.切换选项卡 在tabControl控件上用虚拟画布的方式绘制了一幅画贴在了一个选项卡空白处,可是当最小化和切换选项卡的时候,图像消失了,怎样解决? Bitmap image = new Bitmap(690, 400); // 这里绘制image tabPage2.CreateGraphics().DrawImage(image, 0, 0); 解决方案 顶一下,不要沉下去~~ 解决方案二: 还是没有哪位大

tabpage-C# tabcontrol控件,插入背景图片

问题描述 C# tabcontrol控件,插入背景图片 C# tabcontrol控件,怎么在每一个tabpage的框里插入不同的背景图片,急,在线等 解决方案 选择每个tabpage,在里面找BackgroundImage属性,浏览,加载一个图片. 解决方案二: C# 设置控件的背景图片

vs2008 [WinForm] TabControl控件问题...

问题描述 TabControl控件里的TabPage怎么没有Visible和Enabled属性呢?请问高手们,我怎么禁用TabPage呢? 解决方案 解决方案二:想禁用TabPage可以在tabControl1_Selecting事件中处理.参考:privatevoidtabControl1_Selecting(objectsender,TabControlCancelEventArgse){if(e.TabPageIndex==2)e.Cancel=true;//如果想disableTabPa

针对BootStrap中tabs控件的美化和完善(推荐)_javascript技巧

BootStrap中的tabs控件以其简单易用而很受广大开发者的欢迎.但是,它的样式比较单一,如何才能在其原有的基础上做出更加美观的效果呢,我一直在考虑这个问题.另外,Bootstrap中的tabs必须要单击每个选项卡才能实现切换,能否使用Jquery来控制其自动切换,让它过一段时间(如5秒钟)从一个选项卡切换到另一个呢?下面是我的实现过程,首先是tabs部分的html代码: <div class="tab" role="tabpanel"> <!

模仿combox(select)控件 省去美化烦恼

select|控件 不用整天为美化select控件烦恼了. 1.可批量美化select控件. 2.可以有onchange句柄. 3.触发onchange的函数可带参数. 3.可以得到select的值. 4.可设置像select类似的滚动条(如大于或等于8个数目时出现滚动条) 5.可设置宽度和高度 API参考: //首先生成一个simulateSelect的实例 //构造函数的第一个可选参数为触发onchange的函数,其它的为onchange函数的参数; c = new simulateSele

如何去掉TabControl控件默认添加的TabPage

把TabControl添加到设计器的时候,默认会添加两个TabPage,当继承 TabControl自定义控件的时候,这两个默认的TabPage常常会制造一些麻烦,今 天我来介绍一种方法来去掉这两个默认的TabPage: 实际上思路比较简单,主要是通过ToolboxItem特性提供自定义的 ToolboxItem类来修改工具箱中的控件的初始化工程,只需要继承ToolboxItem类 ,重写CreateComponentsCore方法就可以实现了: [ToolboxItem(typeof(Demo

关于在tabcontrol控件上画图

问题描述 tabcontrol标签2页面放了一个panel1控件在loadshown事件中都增加了Graphicsg=panel1.CreateGraphics();Rectanglerect=newRectangle(panel1.ClientRectangle.X,panel1.ClientRectangle.Y,panel1.ClientRectangle.X+panel1.ClientRectangle.Width+5,panel1.ClientRectangle.Y+panel1.Cl