在www.codeproject.com 看到一个关于重绘tabControl的例了,觉得挺有意思的。照着修改一下,有一些东西自己并没有去改,使得代码很短,同时也有一些功能并没实现的。具休可到http://www.codeproject.com/KB/tabs/flattabcontrol.aspx。

我实现的效果如图:

代码实现

主要是对TabControl实现的重绘,可以通过继承TabControl来重绘。

基本上没什么难度,有兴趣可以试着写一下。

vb.net IC交易网代码如下:

view plaincopy to clipboardprint?
Imports System.Drawing  
 
Imports System.Drawing.Drawing2D  
 
Imports System.Collections  
 
Imports System.ComponentModel  
 
Imports System.Collections.Generic  
 
Public Class FlatControl  
 
 
 
    Sub New()  
 
 
 
        ' 此调用是 Windows 窗体设计器所必需的。  
 
        InitializeComponent()  
 
 
 
        ' 在 InitializeComponent()  pdf调用之后添加任何初始化。  
 
        SetStyle(ControlStyles.AllPaintingInWmPaint, True)  
 
        SetStyle(ControlStyles.OptimizedDoubleBuffer, True)  
 
        SetStyle(ControlStyles.StandardDoubleClick, True)  
 
        SetStyle(ControlStyles.ResizeRedraw, True)  
 
        SetStyle(ControlStyles.UserPaint, True)  
 
    End Sub 
 
 
 
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)  
 
        MyBase.OnPaint(e)  
 
        DrawTagControl(e.Graphics)  
 
    End Sub 
 
    Dim _backColor As Color = SystemColors.Control  
 
    Public Property backColors() As Color  
 
        Get 
 
            Return _backColor  
 
        End Get 
 
        Set(ByVal value As Color)  
 
            _backColor = value  
 
        End Set 
 
    End Property 
 
 
 
    Dim _borderWidth As Integer = SystemInformation.Border3DSize.Width  
 
    Public Property borderWidth() As Integer 
 
        Get 
 
            Return _borderWidth  
 
        End Get 
 
        Set(ByVal value As Integer)  
 
            _borderWidth = value  
 
        End Set 
 
    End Property 
 
 
 
    Dim _borderColor As Color = SystemColors.ControlDark  
 
 
 
 
 
    Public Property borderColor() As Color  
 
        Get 
 
            Return _borderColor  
 
        End Get 
 
        Set(ByVal value As Color)  
 
            _borderColor = value  
 
        End Set 
 
    End Property 
 
    Sub DrawTagControl(ByVal g As Graphics)  
 
        If Me.Visible = False Then 
 
            Exit Sub 
 
        End If 
 
 
 
        Dim BackTabArea As Rectangle = Me.ClientRectangle  
 
        Dim UserArea As Rectangle = Me.DisplayRectangle  
 
 
 
 
 
        'draw AllArea  
 
        Dim BackBrush As New SolidBrush(backColors)  
 
        g.FillRectangle(BackBrush, BackTabArea)  
 
        BackBrush.Dispose()  
 
 
 
 
 
        'draw border   
 
        Dim BrPen As New Pen(borderColor, borderWidth)  
 
        UserArea.Inflate(borderWidth, borderWidth)  
 
        g.DrawRectangle(BrPen, UserArea)  
 
        BrPen.Dispose()  
 
 
 
        If Me.TabCount > 0 Then 
 
 
 
            For i As Integer = 0 To Me.TabCount - 1  
 
                DrawTabs(g, TabPages(i), i)  
 
            Next 
 
 
 
        End If 
 
        If Me.SelectedTab IsNot Nothing Then 
 
            Dim tabPage As TabPage = Me.SelectedTab  
 
            Dim color As Color = tabPage.BackColor  
 
            Dim bpen As New Pen(color)  
 
            UserArea.Offset(1, 1)  
 
            UserArea.Width -= 2  
 
            UserArea.Height -= 2  
 
            g.DrawRectangle(bpen, UserArea)  
 
            UserArea.Width -= 1  
 
            UserArea.Height -= 1  
 
            g.DrawRectangle(bpen, UserArea)  
 
            bpen.Dispose()  
 
        End If 
 
 
 
 
 
 
 
    End Sub 
 
 
 
 
 
    Sub DrawTabs(ByVal g As Graphics, ByVal tabpage As TabPage, ByVal Tindex As Integer)  
 
 
 
        Dim TabArea As Rectangle = Me.GetTabRect(Tindex)  
 
        Dim TabTextArea As RectangleF = Me.GetTabRect(Tindex)  
 
 
 
        Dim point0 As Point  
 
        Dim point1 As Point  
 
        Dim point2 As Point  
 
        Dim point3 As Point  
 
        Dim point4 As Point  
 
        Dim point5 As Point  
 
        Dim point6 As Point  
 
 
 
 
 
        '只写top与下两个方向的  
 
        If Me.Alignment = TabAlignment.Top Then 
 
            point0 = New Point(TabArea.Left + borderWidth, TabArea.Bottom + 2)  
 
            point1 = New Point(TabArea.Left + borderWidth, TabArea.Top + 3)  
 
            point2 = New Point(TabArea.Left + borderWidth + 3, TabArea.Top)  
 
            point3 = New Point(TabArea.Right - 3, TabArea.Top)  
 
            point4 = New Point(TabArea.Right, TabArea.Top + 3)  
 
            point5 = New Point(TabArea.Right, TabArea.Bottom + 2)  
 
            point6 = point0  
 
        ElseIf Me.Alignment = TabAlignment.Bottom Then 
 
            point0 = New Point(TabArea.Left, TabArea.Top + 2)  
 
            point1 = New Point(TabArea.Left, TabArea.Bottom - 3)  
 
            point2 = New Point(TabArea.Left + 3, TabArea.Bottom)  
 
            point3 = New Point(TabArea.Right - 3, TabArea.Bottom)  
 
            point4 = New Point(TabArea.Right, TabArea.Bottom - 3)  
 
            point5 = New Point(TabArea.Right, TabArea.Top + 2)  
 
            point6 = point0  
 
 
 
        End If 
 
 
 
        Dim pt() As Point = New Point() {point0, point1, point2, point3, point4, point5, point6}  
 
        '添充  
 
        Dim bBrush As New SolidBrush(tabpage.BackColor)  
 
        g.FillPolygon(bBrush, pt)  
 
        bBrush.Dispose()  
 
 
 
        Dim pt1() As Point = New Point() {point0, point1, point2, point3, point4, point5}  
 
        '画边  
 
        Dim bpen As New Pen(borderColor, borderWidth)  
 
        g.DrawPolygon(bpen, pt1)  
 
        bpen.Dispose()  
 
 
 
 
 
        'draw Image   
 
        If tabpage.ImageIndex >= 0 Then 
 
            Dim LeftSpace As Integer = 8  
 
            Dim Topspace As Single 
 
            Dim img As Image = ImageList.Images(tabpage.ImageIndex)  
 
            Topspace = (TabTextArea.Height - img.Height) / 2 + 1  
 
            g.DrawImage(img, New PointF(LeftSpace + TabTextArea.X, Topspace))  
 
            TabTextArea.Width = TabTextArea.Width - LeftSpace + img.Width  
 
        End If 
 
 
 
        'drawText   
 
        Dim stringFormat As New StringFormat  
 
        stringFormat.Alignment = StringAlignment.Center  
 
        stringFormat.LineAlignment = StringAlignment.Center  
 
        g.DrawString(TabPages(Tindex).Text, Me.Font, Brushes.Black, TabTextArea, stringFormat)  
 
 
 
    End Sub 
 
 
 
    Private Sub FlatControl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.SelectedIndexChanged  
 
        Me.Invalidate()  
 
    End Sub 
 
 
 
End Class

转载于:https://www.cnblogs.com/aspxnets/archive/2011/06/29/2093812.html

用ASP.NET 重绘TabControl代码相关推荐

  1. c#-winform重绘Tabcontrol控件,标签带Logo图标

    模仿网页浏览器标签重绘Tabcontrol控件,每个标签页左上角的Logo图标可以自定义,当然图标也可以挪到右边,直接上图.

  2. C# 重绘tabControl,添加关闭按钮(续)

    在上一篇随笔中,添加关闭按钮是可以实现 ,但细心一点就会发现,每次关闭一个选项卡,tableControl都会自动跳到第一个页面,显然 这不是我们想要的,为此,我修改了部分的代码.除此之外,我还添加了 ...

  3. C#中关于WinForm中重绘TabControl选项卡标题的问题

    这里说的是每个TabPage的头部,也就是标题,不是工作区域. 最开始用到TabControl的时候,我的每个选项卡是写死的,而后由于项目需求又动态添加了TabControl并生成各个选项卡,而两次我 ...

  4. C#重绘TabControl控件的源码(转)

    代码   1using System;   2 using System.Collections.Generic;   3 using System.ComponentModel;   4 using ...

  5. java画笔覆盖在界面_Java实现画图程序和重绘

    上次聊了一下事件监听机制,今天就来聊一下怎么实现一个画图程序并且实现重绘. 一.实现画图程序 1.实现一个画图程序所需的API类? JFrame窗体容器组件类 JPanel 面板元素组件类 JButt ...

  6. 【转】高性能WEB开发系列之重绘与回流

    原文转载:http://www.cnblogs.com/wangzhichao/archive/2011/05/16/2047633.html 页面呈现流程 在讨论页面重绘.回流之前.需要对页面的呈现 ...

  7. 页面重绘和回流以及优化

    在讨论页面重绘.回流之前.需要对页面的呈现流程有些了解,页面是怎么把html结合css等显示到浏览器上的,下面的流程图显示了浏览器对页面的呈现的处理流程.可能不同的浏览器略微会有些不同.但基本上都是类 ...

  8. 28、深入浅出MFC学习笔记,View功能的加强和重绘效率的提高

    1.同一份Document的多个views,在Document的一个view改变了后,如何同步其它view呢? 让所有的Views 同步更新资料的关键在于两个函数: 1)CDocument::Upda ...

  9. 孙鑫-MFC笔记六--绘图,重绘

    Windows颜色对话框功能的添加: MFC提供了CColorDialog类,方便创建颜色对话框. CColorDialog dlg: dlg.DoModal(); 默认为黑色.即首参为值为0. 保存 ...

最新文章

  1. threadlocal使用场景_深入剖析ThreadLocal
  2. 手握173篇论文的学术新星被指造假!后续:博士论文被召回
  3. java html提取_如何用JAVA从HTML源代码中提取有用的文本信息?
  4. 【BZOJ3555】[Ctsc2014]企鹅QQ hash
  5. Zxing二维码的集成使用
  6. T-SQL笔记6:GO
  7. javaScript学习笔记之比较运算符||逻辑运算符||条件运算符(三目运算符)
  8. 存储过程从入门到熟练(多个存储过程完整实例及调用方法)_AX
  9. [css] 怎么让div中的图片和文字同时上下居中?
  10. 给你的Linux把把脉(内存、磁盘、CPU、网络)
  11. 腾讯视频怎么开启禁止界面硬件加速
  12. pythonlinux安装 pandas_linux pandas安装
  13. Netty 学习笔记(已完结)
  14. 如来分形 大圣败北 ——如来会分形的取证调查
  15. 关于抖音抓包的一些分析和抖音视频批量下载
  16. 手札-11(京东实战手札)
  17. 2019数博会参会嘉宾数量、层级、范围创历届新高,全球领袖级企业竞相亮相
  18. 「什么是REITs基金」一文说清楚REITs基金简介 如何配置REITs产品
  19. session值为空,thymeleaf报错
  20. RF+jenkins持续集成

热门文章

  1. javaweb k8s_阿里云部署K8Sweb项目
  2. 循环节长度 java,第六届蓝桥杯java试题-循环节长度
  3. 绘制多个折线图_学习笔记第一页 | 常用统计图绘制及描述规范
  4. 看图说话:用户标签可以这样轻松创建
  5. 【HTML】------HTML的标签
  6. Linux上常用命令整理(二)—— paste
  7. Linux内核源码树建立加载hello模块
  8. eclipse更改Server Location的问题
  9. tenjin - 号称全球最快的模板引擎
  10. 【转】C# 正则表达式 使用介绍