📄 tabcontrol.vb
字号:
Imports System.ComponentModel
<DesignTimeVisible(True)> _
Public Class TabControl
#Region " Class GetTabRegionEventArgs "
<Description("Provides data for the MdiTabControl.TabControl.GetTabRegion event.")> _
Public Class GetTabRegionEventArgs
Inherits System.EventArgs
Private m_Points() As Point
Private m_TabWidth As Integer
Private m_TabHeight As Integer
Private m_Selected As Boolean
Private Sub New()
End Sub
<Description("Initializes a new instance of the MdiTabControl.TabControl.GetTabRegionEventArgs class.")> _
Public Sub New(ByVal Points() As Point, ByVal Width As Integer, ByVal Height As Integer, ByVal Selected As Boolean)
MyBase.new()
m_Points = Points
m_TabWidth = Width
m_TabHeight = Height
m_Selected = Selected
End Sub
<Description("Returns whether the tab is selected or not.")> _
Public ReadOnly Property Selected() As Integer
Get
Return m_Selected
End Get
End Property
<Description("Returns the tab width.")> _
Public ReadOnly Property TabWidth() As Integer
Get
Return m_TabWidth
End Get
End Property
<Description("Returns the tab height.")> _
Public ReadOnly Property TabHeight() As Integer
Get
Return m_TabHeight
End Get
End Property
<Description("Gets or sets an array of System.Drawing.Point structures that represents the points through which the tab path is constructed.")> _
Public Property Points() As Point()
Get
Return m_Points
End Get
Set(ByVal value As Point())
m_Points = value
End Set
End Property
End Class
#End Region
#Region " Class TabPaintEventArgs "
<Description("Provides data for the MdiTabControl.TabControl.TabPaint event.")> _
Public Class TabPaintEventArgs
Inherits PaintEventArgs
Private m_Handled As Boolean = False
Private m_Selected As Boolean = False
Private m_Hot As Boolean = False
Private m_GraphicPath As Drawing2D.GraphicsPath
Private m_TabWidth As Integer
Private m_TabHeight As Integer
<Description("Initializes a new instance of the MdiTabControl.TabControl.GetTabRegionEventArgs class.")> _
Public Sub New(ByVal graphics As Graphics, ByVal clipRect As Rectangle, ByVal Selected As Boolean, ByVal Hot As Boolean, ByVal GraphicPath As Drawing2D.GraphicsPath, ByVal Width As Integer, ByVal Height As Integer)
MyBase.New(graphics, clipRect)
m_Selected = Selected
m_Hot = Hot
m_GraphicPath = GraphicPath
m_TabWidth = Width
m_TabHeight = Height
End Sub
<Description("Returns the tab's hot state.")> _
Public ReadOnly Property Hot() As Boolean
Get
Return m_Hot
End Get
End Property
<Description("Returns whether the tab is selected or not.")> _
Public ReadOnly Property Selected() As Boolean
Get
Return m_Selected
End Get
End Property
<Description("Gets or sets a value that indicates whether the event handler has completely handled the paint or whether the system should continue its own processing.")> _
Public Property Handled() As Boolean
Get
Return m_Handled
End Get
Set(ByVal value As Boolean)
m_Handled = value
End Set
End Property
<Description("Returns the tab width.")> _
Public ReadOnly Property TabWidth() As Integer
Get
Return m_TabWidth
End Get
End Property
<Description("Returns the tab height.")> _
Public ReadOnly Property TabHeight() As Integer
Get
Return m_TabHeight
End Get
End Property
<Description("Represents a series of connected lines and curves which the tab path is constructed.")> _
Public ReadOnly Property GraphicPath() As Drawing2D.GraphicsPath
Get
Return m_GraphicPath
End Get
End Property
End Class
#End Region
#Region " Class TabPageCollection "
<Description("Contains a collection of MdiTabControl.TabPage objects.")> _
Public Class TabPageCollection
Inherits CollectionBase
Private TabControl As TabControl
Private IsReorder As Boolean = False
Friend Event GetTabRegion(ByVal sender As Object, ByVal e As TabControl.GetTabRegionEventArgs)
<Description("Occurs when the Tab Background has been painted.")> _
Friend Event TabPaintBackground(ByVal sender As Object, ByVal e As TabControl.TabPaintEventArgs)
<Description("Occurs when the Tab Border has been painted.")> _
Friend Event TabPaintBorder(ByVal sender As Object, ByVal e As TabControl.TabPaintEventArgs)
Friend Event SelectedChanged As EventHandler
Friend Sub New(ByVal Owner As TabControl)
TabControl = Owner
End Sub
<Description("Create a new TabPage and adds it to the collection whit the Form associated and returns the created TabPage.")> _
Public Function Add(ByVal Form As Form) As TabPage
Dim TabPage As New TabPage(Form)
TabPage.SuspendLayout()
TabControl.SuspendLayout()
' Initialize all the tabpage defaults values
TabControl.AddingPage = True
TabPage.BackHighColor = TabControl.TabBackHighColor
TabPage.BackHighColorDisabled = TabControl.TabBackHighColorDisabled
TabPage.BackLowColor = TabControl.TabBackLowColor
TabPage.BackLowColorDisabled = TabControl.TabBackLowColorDisabled
TabPage.BorderColor = TabControl.BorderColor
TabPage.BorderColorDisabled = TabControl.BorderColorDisabled
TabPage.ForeColor = TabControl.ForeColor
TabPage.ForeColorDisabled = TabControl.ForeColorDisabled
TabPage.MaximumWidth = TabControl.TabMaximumWidth
TabPage.MinimumWidth = TabControl.TabMinimumWidth
TabPage.PadLeft = TabControl.TabPadLeft
TabPage.PadRight = TabControl.TabPadRight
TabPage.CloseButtonVisible = TabControl.TabCloseButtonVisible
TabPage.CloseButtonImage = TabControl.TabCloseButtonImage
TabPage.CloseButtonImageHot = TabControl.TabCloseButtonImageHot
TabPage.CloseButtonImageDisabled = TabControl.TabCloseButtonImageDisabled
TabPage.CloseButtonSize = TabControl.TabCloseButtonSize
TabPage.CloseButtonBackHighColor = TabControl.TabCloseButtonBackHighColor
TabPage.CloseButtonBackLowColor = TabControl.TabCloseButtonBackLowColor
TabPage.CloseButtonBorderColor = TabControl.TabCloseButtonBorderColor
TabPage.CloseButtonForeColor = TabControl.TabCloseButtonForeColor
TabPage.CloseButtonBackHighColorDisabled = TabControl.TabCloseButtonBackHighColorDisabled
TabPage.CloseButtonBackLowColorDisabled = TabControl.TabCloseButtonBackLowColorDisabled
TabPage.CloseButtonBorderColorDisabled = TabControl.TabCloseButtonBorderColorDisabled
TabPage.CloseButtonForeColorDisabled = TabControl.TabCloseButtonForeColorDisabled
TabPage.CloseButtonBackHighColorHot = TabControl.TabCloseButtonBackHighColorHot
TabPage.CloseButtonBackLowColorHot = TabControl.TabCloseButtonBackLowColorHot
TabPage.CloseButtonBorderColorHot = TabControl.TabCloseButtonBorderColorHot
TabPage.CloseButtonForeColorHot = TabControl.TabCloseButtonForeColorHot
TabPage.HotTrack = TabControl.HotTrack
TabPage.Font = TabControl.Font
TabPage.FontBoldOnSelect = TabControl.FontBoldOnSelect
TabPage.IconSize = TabControl.TabIconSize
TabPage.SmoothingMode = TabControl.SmoothingMode
TabPage.Alignment = TabControl.Alignment
TabPage.GlassGradient = TabControl.TabGlassGradient
TabPage.BorderEnhanced = TabControl.m_TabBorderEnhanced
TabPage.RenderMode = TabControl.RenderMode
TabPage.BorderEnhanceWeight = TabControl.TabBorderEnhanceWeight
TabPage.Top = 0
TabPage.Left = TabControl.LeftOffset
TabPage.Height = TabControl.TabHeight
TabControl.TabToolTip.SetToolTip(TabPage, TabPage.m_Form.Text)
' Create the event handles
AddHandler TabPage.Click, AddressOf TabPage_Clicked
AddHandler TabPage.Close, AddressOf TabPage_Closed
AddHandler TabPage.GetTabRegion, AddressOf TabPage_GetTabRegion
AddHandler TabPage.TabPaintBackground, AddressOf TabPage_TabPaintBackground
AddHandler TabPage.TabPaintBorder, AddressOf TabPage_TabPaintBorder
AddHandler TabPage.SizeChanged, AddressOf TabPage_SizeChanged
AddHandler TabPage.Draging, AddressOf TabPage_Draging
AddHandler TabPage.EnterForm, AddressOf TabPage_Enter
AddHandler TabPage.LeaveForm, AddressOf TabPage_Leave
' Insert the tabpage in the collection
List.Add(TabPage)
TabControl.ResumeLayout()
TabPage.ResumeLayout()
Return TabPage
End Function
<Description("Removes a TabPage from the collection.")> _
Public Sub Remove(ByVal TabPage As TabPage)
Try
TabControl.IsDelete = True
If TabControl.pnlBottom.Controls.Count > 1 Then
' brings the next top tab
' first dock the form in the body then display it
TabControl.pnlBottom.Controls(1).Dock = DockStyle.Fill
TabControl.pnlBottom.Controls(1).Visible = True
End If
List.Remove(TabPage)
Catch ex As Exception
End Try
End Sub
<Description("Gets a TabPage in the position Index from the collection.")> _
Default Public ReadOnly Property Item(ByVal Index As Integer) As TabPage
Get
Return List.Item(Index)
End Get
End Property
<Description("Gets a TabPage associated with the Form from the collection.")> _
Default Public ReadOnly Property Item(ByVal Form As Form) As TabPage
Get
Dim x As Integer = IndexOf(Form)
If x = -1 Then
Return Nothing
Else
Return List.Item(x)
End If
End Get
End Property
<Description("Returns the index of the specified TabPage in the collection.")> _
Public Property IndexOf(ByVal TabPage As TabPage) As Integer
Get
Return List.IndexOf(TabPage)
End Get
Set(ByVal value As Integer)
IsReorder = True
List.Remove(TabPage)
List.Insert(value, TabPage)
TabControl.ArrangeItems()
IsReorder = False
End Set
End Property
<Description("Returns the index of the specified TabPage associated with the Form in the collection.")> _
Public ReadOnly Property IndexOf(ByVal Form As Form) As Integer
Get
Dim ret As Integer = -1
For i As Integer = 0 To List.Count - 1
If DirectCast(List(i), TabPage).m_Form.Equals(Form) Then
ret = i
Exit For
End If
Next
Return ret
End Get
End Property
Protected Overrides Sub OnInsertComplete(ByVal index As Integer, ByVal value As Object)
MyBase.OnInsertComplete(index, value)
If IsReorder Then Exit Sub
' insert the controls in the respective containers
TabControl.pnlBottom.Controls.Add(DirectCast(value, TabPage).m_Form)
TabControl.pnlTabs.Controls.Add(DirectCast(value, TabPage))
' select the inserted tabpage
DirectCast(value, TabPage).Select()
TabControl.AddingPage = False
TabControl.ArrangeItems()
TabControl.Background.Visible = False
End Sub
Protected Overrides Sub OnRemoveComplete(ByVal index As Integer, ByVal value As Object)
MyBase.OnRemoveComplete(index, value)
If IsReorder Then Exit Sub
If List.Count = 0 Then TabControl.Background.Visible = True
TabControl.ArrangeItems()
TabControl.pnlBottom.Controls.Remove(DirectCast(value, TabPage).m_Form)
DirectCast(value, TabPage).m_Form.Dispose()
TabControl.pnlTabs.Controls.Remove(DirectCast(value, TabPage))
DirectCast(value, TabPage).Dispose()
TabControl.SelectItem(Nothing)
End Sub
Protected Overrides Sub OnClear()
MyBase.OnClear()
TabControl.Background.Visible = True
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -