tabcontrol在切换页面的时候经常用到

这里讲下如何让tabcontrol更好看

ref:http://blog.csdn.net/conmajia/article/details/7596718

http://wenku.baidu.com/link?url=y4BdtX3mOer4Hdin019jJpXJLi-2_ehmEo7i08cxEp1OR_3gb5CqaHrnNEB2iLQyNDqpkNtnuREmn4GWpur081mIPuNH-1184wLkFzsVuEq

一。 创建一个类,加引用,using什么的,TabControlEx的基类为System.Windows.Forms.TabControl

二。加代码

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 using System.Drawing;
 using System.Drawing.Drawing2D;

 namespace MyTabControl
 {
     public class TabControlEx : System.Windows.Forms.TabControl
     {
         Image backImage;
         public TabControlEx()
         {
             base.SetStyle(
                 ControlStyles.UserPaint |
                 ControlStyles.OptimizedDoubleBuffer |
                 ControlStyles.ResizeRedraw |
                 ControlStyles.SupportsTransparentBackColor,
                 true);
             base.Update();
             this.SizeMode = TabSizeMode.Fixed;
             , );
             backImage = new Bitmap(this.GetType(), "MyTabControl.bmp");
         }
         Form oldman;
         protected override void OnParentChanged(EventArgs e)
         {
             if (oldman == null) oldman = this.FindForm();
             oldman.Text = ].Text;
         }
         protected override void OnSelected(TabControlEventArgs e)
         {
             Parent.Text = e.TabPage.Text;
         }
         protected override void OnPaint(PaintEventArgs e)
         {
             e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
             ; i < this.TabCount; i++)
             {
                 //e.Graphics.DrawRectangle(Pens.Red, this.GetTabRect(i));
                 if (this.SelectedIndex == i)
                 {
                     e.Graphics.DrawImage(backImage, this.GetTabRect(i));
                 }
                 Rectangle bounds = this.GetTabRect(i);
                 PointF textPoint = new PointF();
                 SizeF textSize = TextRenderer.MeasureText(this.TabPages[i].Text, this.Font);
                 textPoint.X = bounds.X + (bounds.Width - textSize.Width) / ;
                 textPoint.Y = bounds.Bottom - textSize.Height - this.Padding.Y;
                 e.Graphics.DrawString(
                     this.TabPages[i].Text,
                     this.Font,
                     SystemBrushes.ControlLightLight,
                     textPoint.X,
                     textPoint.Y);
                 textPoint.Y--;
                 e.Graphics.DrawString(
                     this.TabPages[i].Text,
                     this.Font,
                     SystemBrushes.ControlText,
                     textPoint.X,
                     textPoint.Y);
                 if (this.ImageList != null)
                 {
                     int index = this.TabPages[i].ImageIndex;
                     string key = this.TabPages[i].ImageKey;
                     Image icon = , );
                     )
                     {
                         icon = this.ImageList.Images[index];
                     }
                     if (!string.IsNullOrEmpty(key))
                     {
                         icon = this.ImageList.Images[key];
                     }
                     e.Graphics.DrawImage(
                         icon,
                         bounds.X + (bounds.Width - icon.Width) / ,
                         bounds.Top + this.Padding.Y);
                 }
             }
         }
     }
 }

三。加imagelist,并且为tabcontrol里的tabpage设置imageindex和imageKey

四。将此类加入工具箱中,注意将该项目的属性里的调试改为外部程序调试

C#控件:TabControl的更多相关文章

  1. [C#开发小技巧]解决WinForm控件TabControl闪烁问题

    在用C#开发WinForm程序时,常发现TabControl出现严重的闪烁问题,这主要是由于TabControl控件在实现时会绘制默认的窗口背景.其实以下一段简单的代码可以有效的缓解该问题的发生.这就 ...

  2. C#控件TabControl隐藏page

    隐藏 这个需求其实就是TABCONTROL控件会有很多提前制作好的PAGE页面,每次软件启动不可能所有页面都显示出来,目前想了个比较简单的方法解决这个问题 首先定义一个List集合存储TABCONTR ...

  3. Access-自定义控件TabControl

    p{ font-size: 15px; } .alexrootdiv>div{ background: #eeeeee; border: 1px solid #aaa; width: 99%; ...

  4. C# Winform关于控件TabControl闪烁的问题

    自己重写了一个Form,然后再该form上放一个TabControl鼠标移上去会闪烁,经过网上查找解决方案,最后总算是解决了....下面附上代码: 重写一个TabControl代码如下: using ...

  5. WINFORM控件tabcontrol,隐藏,调用等等

    1先说显示项的控制, 第一个是selectedIndex属性这个实用性不是太强,但是如果不涉及到隐藏,删除,增加tabpage的话,也可以用. 第二个是selectedTab=tabPage1,这个属 ...

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

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

  7. .net中,控件(Name)属性或ID属性的常见命名规则

    控件名称 缩写 介绍 公共控件   Button btn 按钮 CheckBox chk 复选框 CheckedListBox ckl 显示一个项列表,其中每一项左侧都有一个复选框 ComboBox ...

  8. WPF学习(三)--Menu、TabControl和DataGrid控件介绍

    Menu Menu提供了菜单栏方式的多级菜单的管理和操作: 这里对Menu的样式不做任何的定制和管理 下面来对Menu进行测试: 将Menu添加到页面中 运行后,效果如下: 这里没有考虑界面效果和样式 ...

  9. WPF中viewmodel层怎样得到view层的TabControl控件对象?

    View层: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: ...

  10. TabControl控件的美化

    文件下载:http://files.cnblogs.com/zfanlong1314/TabControlEX.rar 本文转载:http://www.cnblogs.com/lmlblog/arch ...

随机推荐

  1. Arrays.toString Arrays.asList

    import java.util.Arrays; public class TestCalc{ public static void main(String[] args) { ,,,,,,,}; / ...

  2. 单选按钮控件(Ridio Button)的使用

    VC学习笔记5:单选按钮控件(Ridio Button)的使用 一.对单选按钮进行分组: 每组的第一个单选按钮设置属性:Group,Tabstop,Auto;其余按钮设置属性Tabstop,Auto. ...

  3. Bluetooth数据包捕获

    目录 1. 前提 2. 开启功能 3. 抓包 这里介绍一种在Android上捕获蓝牙数据包的方法 1. 前提 首先你要有一部Android手机 然后你的Android系统版本要在4.4及以上 我没有做 ...

  4. 关于HBase的概述

    1.hbase的特点 ->数据存储量可以达到亿级别数据维持在秒级 ->按列存储的数据库 ->能够存储上百万列 ->hbase的底层存储依赖于HDFS ->如何扩展hbas ...

  5. 【Java 基础篇】【第十课】多态

    Java的多态使用方法和C++基本是一样的. 看代码吧. public class ten { public static void main(String[] args) { Human guest ...

  6. wpf前端设计

    http://www.cnblogs.com/w-wanglei/archive/2016/03/14/5274298.html#_nav_0

  7. CentOS7+Redis Live安装配置

    Redis Live是一个用来监控redis实例,分析查询语句并且有web界面的监控工具,使用python编写. 代码下载地址:https://github.com/nkrode/RedisLive ...

  8. eclipse根据.wsdl文件自动生成webservice的调用客户端

    1.工具:eclipse3.3或者是带有webservice插件的eclipse 2. 首先用浏览器访问webservice的站点,接着保存打开的页面,后缀为.wsdl. 3.把保存好的文件拷入ecl ...

  9. Tea---hdu5881(规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5881 题意: 现在有一壶水,体积在[L, R]范围内,现有两个空杯子,现想要把这壶水倒入这两个杯子中去 ...

  10. Sql server与Excel的数据互通导入导出

    现在,我先从Sql server数据表导出到Excel中,再从Excel数据表导出到Sql server中: 一.Sql server数据表导出到Excel中: 1.新建一个Excel,选择“数据”菜 ...