日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

用ASP.NET 重绘TabControl代码

發布時間:2025/3/17 asp.net 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用ASP.NET 重绘TabControl代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

 在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代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。