📄 tabpage.vb
字号:
' Draws the Close Button
Private Sub DrawCloseButton(ByVal g As Graphics)
Try
Dim I As Bitmap
Dim x As Integer = Me.Width - (m_CloseButtonSize.Width + PadRight + 2)
Dim y As Integer = Me.Height / 2 - m_CloseButtonSize.Height / 2
If MouseOverCloseButton Then
I = m_CloseButtonImageHot
ElseIf m_Selected Then
I = m_CloseButton
Else
I = m_CloseButtonImageDisabled
End If
Dim IsDisposable As Boolean = False
If I Is Nothing Then
I = GetButton()
IsDisposable = True
End If
Dim icon As Icon = Drawing.Icon.FromHandle(I.GetHicon)
Dim r As Rectangle = New Rectangle(x, y, m_CloseButtonSize.Width, m_CloseButtonSize.Height)
g.DrawIcon(icon, r)
If IsDisposable Then
I.Dispose()
I = Nothing
End If
DestroyIcon(icon.Handle)
icon.Dispose()
icon = Nothing
Catch ex As Exception
End Try
End Sub
' Generates the close button image
Private Function GetButton() As Bitmap
Dim Points() As System.Drawing.Point = {New Point(1, 0), New Point(3, 0), New Point(5, 2), New Point(7, 0), New Point(9, 0), New Point(6, 3), New Point(6, 4), New Point(9, 7), New Point(7, 7), New Point(5, 5), New Point(3, 7), New Point(1, 7), New Point(4, 4), New Point(4, 3)}
Dim gp As New Drawing2D.GraphicsPath
Dim bch As Color
Dim bcl As Color
Dim bc As Color
Dim fc As Color
Dim B As Bitmap
Dim m As New Drawing2D.Matrix
Dim path() As System.Drawing.Point = {New Point(0, 1), New Point(1, 0), New Point(15, 0), New Point(16, 1), New Point(16, 14), New Point(15, 15), New Point(1, 15), New Point(0, 14)}
Dim g As Graphics
If MouseOverCloseButton Then
bch = RenderColors.TabCloseButtonBackHighColorHot(m_RenderMode, CloseButtonBackHighColorHot)
bcl = RenderColors.TabCloseButtonBackLowColorHot(m_RenderMode, CloseButtonBackLowColorHot)
bc = RenderColors.TabCloseButtonBorderColorHot(m_RenderMode, CloseButtonBorderColorHot)
fc = RenderColors.TabCloseButtonForeColorHot(m_RenderMode, CloseButtonForeColorHot)
ElseIf m_Selected Then
bch = RenderColors.TabCloseButtonBackHighColor(m_RenderMode, CloseButtonBackHighColor)
bcl = RenderColors.TabCloseButtonBackLowColor(m_RenderMode, CloseButtonBackLowColor)
bc = RenderColors.TabCloseButtonBorderColor(m_RenderMode, CloseButtonBorderColor)
fc = RenderColors.TabCloseButtonForeColor(m_RenderMode, CloseButtonForeColor)
Else
bch = RenderColors.TabCloseButtonBackHighColorDisabled(m_RenderMode, CloseButtonBackHighColorDisabled)
bcl = RenderColors.TabCloseButtonBackLowColorDisabled(m_RenderMode, CloseButtonBackLowColorDisabled)
bc = RenderColors.TabCloseButtonBorderColorDisabled(m_RenderMode, CloseButtonBorderColorDisabled)
fc = RenderColors.TabCloseButtonForeColorDisabled(m_RenderMode, CloseButtonForeColorDisabled)
End If
B = New Bitmap(17, 17)
B.MakeTransparent()
g = Graphics.FromImage(B)
' draw the border and background
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
Dim l As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, 15), bch, bcl)
g.FillPolygon(l, path)
Dim p As New Pen(bc)
g.DrawPolygon(p, path)
g.SmoothingMode = Drawing2D.SmoothingMode.Default
' draw the foreground
gp.AddPolygon(Points)
m.Translate(3, 4)
gp.Transform(m)
p.Dispose()
p = New Pen(fc)
g.DrawPolygon(p, gp.PathPoints)
Dim sb As New SolidBrush(fc)
g.FillPolygon(sb, gp.PathPoints)
sb.Dispose()
p.Dispose()
gp.Dispose()
g.Dispose()
m.Dispose()
Return B
End Function
' Calculates the tab width
Private Sub CalculateWidth()
Dim g As Graphics = Me.CreateGraphics()
Dim iw As Integer = 0
Dim cbw As Integer = 0
Dim w As Integer = Width
If m_Form.Icon IsNot Nothing Then iw = m_IconSize.Width
If m_CloseButtonVisible Then cbw = m_CloseButtonSize.Width
Dim f As New Font(Font, IIf(m_FontBoldOnSelect, FontStyle.Bold, FontStyle.Regular))
w = PadLeft + iw + 3 + g.MeasureString(m_Form.Text, f).Width + 3 + cbw + m_PadRight + 2
f.Dispose()
If w < m_MinimumWidth + 1 Then
w = m_MinimumWidth + 1
ElseIf w > m_MaximumWidth + 1 Then
w = m_MaximumWidth + 1
End If
If w <> Width Then
Width = w
End If
g.Dispose()
End Sub
' Get the tab region shape
Private Function GetRegion(ByVal W As Integer, ByVal H As Integer, ByVal H1 As Integer) As Point()
Dim R() As Point = {New Point(0, H), New Point(0, 2), New Point(2, 0), New Point(W - 3, 0), New Point(W - 1, 2), New Point(W - 1, H)}
Dim e As New TabControl.GetTabRegionEventArgs(R, W, H, Me.IsSelected)
RaiseEvent GetTabRegion(Me, e)
Array.Resize(e.Points, e.Points.Length + 2)
Array.Copy(e.Points, 0, e.Points, 1, e.Points.Length - 1)
e.Points(0) = New Point(e.Points(1).X, H1)
e.Points(e.Points.Length - 1) = New Point(e.Points(e.Points.Length - 2).X, H1)
Return e.Points
End Function
Private Sub MirrorPath(ByVal GraphicPath As Drawing2D.GraphicsPath)
Dim m As New Matrix
m.Translate(0, Height - 1)
m.Scale(1, -1)
GraphicPath.Transform(m)
m.Dispose()
End Sub
' Paint the tab
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim Painting As Boolean = False
If Painting Then Exit Sub
Painting = True
Me.SuspendLayout()
Dim RenderBorderColor As Color
Dim RenderBottomColor As Color
Dim RenderHighColor As Color
Dim RenderLowColor As Color
Dim GraphicPath As New Drawing2D.GraphicsPath
Dim w As Integer = Me.Width
CalculateWidth()
If w <> Me.Width Then
GraphicPath.Dispose()
Exit Sub
End If
If m_Selected Then
RenderBorderColor = RenderColors.BorderColor(m_RenderMode, BorderColor)
RenderHighColor = RenderColors.TabBackHighColor(m_RenderMode, BackHighColor)
RenderLowColor = RenderColors.TabBackLowColor(m_RenderMode, BackLowColor)
RenderBottomColor = RenderColors.TabBackLowColor(m_RenderMode, BackLowColor)
ElseIf m_Hot Then
RenderBorderColor = RenderColors.BorderColor(m_RenderMode, BorderColor)
RenderHighColor = RenderColors.TabBackHighColor(m_RenderMode, BackHighColor)
RenderLowColor = RenderColors.TabBackLowColor(m_RenderMode, BackLowColor)
RenderBottomColor = RenderColors.BorderColor(m_RenderMode, BorderColor)
Else
RenderBorderColor = RenderColors.BorderColorDisabled(m_RenderMode, BorderColorDisabled)
RenderHighColor = RenderColors.TabBackHighColorDisabled(m_RenderMode, BackHighColorDisabled)
RenderLowColor = RenderColors.TabBackLowColorDisabled(m_RenderMode, BackLowColorDisabled)
RenderBottomColor = RenderColors.BorderColor(m_RenderMode, BorderColor)
End If
e.Graphics.SmoothingMode = m_SmoothingMode
GraphicPath.AddPolygon(GetRegion(Width - 1, Height - 1, IIf(Me.IsSelected, Height, Height - 1)))
' if is bottom mirror the button vertically
If m_Alignment = TabControl.TabAlignment.Bottom Then
MirrorPath(GraphicPath)
Dim x As Color = RenderHighColor
RenderHighColor = RenderLowColor
RenderLowColor = x
End If
' Get the correct region including all the borders
Dim R As Region = New Region(GraphicPath)
Dim R1 As Region = New Region(GraphicPath)
Dim R2 As Region = New Region(GraphicPath)
Dim R3 As Region = New Region(GraphicPath)
Dim M1 As Matrix = New Matrix
Dim M2 As Matrix = New Matrix
Dim M3 As Matrix = New Matrix
M1.Translate(0, -0.5)
M2.Translate(0, 0.5)
M3.Translate(1, 0)
R1.Transform(M1)
R2.Transform(M2)
R3.Transform(M3)
R.Union(R1)
R.Union(R2)
R.Union(R3)
Me.Region = R
Dim RF As RectangleF = R.GetBounds(e.Graphics)
Dim rec As New Rectangle(0, 0, RF.Width, RF.Height)
Dim te As TabControl.TabPaintEventArgs
te = New TabControl.TabPaintEventArgs(e.Graphics, rec, m_Selected, m_Hot, GraphicPath, Width, Height)
RaiseEvent TabPaintBackground(Me, te) ' try to owner draw
Dim gb As LinearGradientBrush = CreateGradientBrush(New Rectangle(0, 0, Me.Width, Me.Height), RenderHighColor, RenderLowColor)
If Not te.Handled Then e.Graphics.FillPath(gb, GraphicPath)
gb.Dispose()
te.Dispose()
te = New TabControl.TabPaintEventArgs(e.Graphics, rec, m_Selected, m_Hot, GraphicPath, Width, Height)
RaiseEvent TabPaintBorder(Me, te) ' try to owner draw
If Not te.Handled Then
If m_BorderEnhanced Then
Dim c As Color = IIf(m_Alignment = TabControl.TabAlignment.Bottom, RenderLowColor, RenderHighColor)
Dim p As New Pen(c, m_BorderEnhanceWeight)
e.Graphics.DrawLines(p, GraphicPath.PathPoints)
p.Dispose()
End If
Dim p1 As New Pen(RenderBorderColor)
e.Graphics.DrawLines(p1, GraphicPath.PathPoints)
p1.Dispose()
End If
te.Dispose()
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.None
e.Graphics.DrawLine(New Pen(RenderBottomColor), GraphicPath.PathPoints(0), GraphicPath.PathPoints(GraphicPath.PointCount - 1))
e.Graphics.SmoothingMode = m_SmoothingMode
DrawIcon(e.Graphics)
DrawText(e.Graphics)
If m_CloseButtonVisible Then DrawCloseButton(e.Graphics)
Me.ResumeLayout()
' do the memory cleanup
GraphicPath.Dispose()
M1.Dispose()
M2.Dispose()
M3.Dispose()
R1.Dispose()
R2.Dispose()
R3.Dispose()
R.Dispose()
te.Dispose()
Painting = False
End Sub
#Region " Obsolete properties "
<EditorBrowsable(EditorBrowsableState.Never)> _
Public Overrides Property MinimumSize() As Size
Get
End Get
Set(ByVal value As Size)
End Set
End Property
<EditorBrowsable(EditorBrowsableState.Never)> _
Public Overrides Property MaximumSize() As Size
Get
End Get
Set(ByVal value As Size)
End Set
End Property
<EditorBrowsable(EditorBrowsableState.Never)> _
Public Shadows Property Padding() As Padding
Get
End Get
Set(ByVal value As Padding)
End Set
End Property
<EditorBrowsable(EditorBrowsableState.Never)> _
Public Overrides Property BackColor() As Color
Get
End Get
Set(ByVal value As Color)
End Set
End Property
<EditorBrowsable(EditorBrowsableState.Never)> _
Public Overrides Property Dock() As System.Windows.Forms.DockStyle
Get
End Get
Set(ByVal value As System.Windows.Forms.DockStyle)
End Set
End Property
<EditorBrowsable(EditorBrowsableState.Never)> _
Public Overrides Property Anchor() As System.Windows.Forms.AnchorStyles
Get
End Get
Set(ByVal value As System.Windows.Forms.AnchorStyles)
End Set
End Property
<EditorBrowsable(EditorBrowsableState.Never)> _
Public Overrides Property Text() As String
Get
Return Nothing
End Get
Set(ByVal value As String)
End Set
End Property
#End Region
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -