Imports System.Collections.Generic
Imports System.Text
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms.VisualStyles
Imports VisualStyles = System.Windows.Forms.VisualStyles
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Collections
Imports System.Windows.Forms.Design
Namespace Messir.Windows.Forms
Public Class SelectedTabChangedEventArgs
Inherits EventArgs
Public ReadOnly SelectedTab As TabStripButton
Public Sub New(ByVal tab As TabStripButton)
SelectedTab = tab
End Sub
End Class
''' <summary>
''' Represents a TabStrip control
''' </summary>
Public Class TabStrip
Inherits ToolStrip
Private myRenderer As New TabStripRenderer()
Protected mySelTab As TabStripButton
Private insPage As DesignerVerb = Nothing
Public Sub New()
MyBase.New()
InitControl()
End Sub
Public Sub New(ByVal ParamArray buttons As TabStripButton())
MyBase.New(buttons)
InitControl()
End Sub
Protected Sub InitControl()
MyBase.RenderMode = ToolStripRenderMode.ManagerRenderMode
MyBase.Renderer = myRenderer
myRenderer.RenderMode = Me.RenderStyle
insPage = New DesignerVerb("Insert tab page", New EventHandler(AddressOf OnInsertPageClicked))
End Sub
Public Overrides Property Site() As ISite
Get
Dim site1 As ISite = MyBase.Site
If site1 IsNot Nothing AndAlso site1.DesignMode Then
Dim comp As IContainer = site1.Container
If comp IsNot Nothing Then
Dim host As IDesignerHost = TryCast(comp, IDesignerHost)
If host IsNot Nothing Then
Dim designer As IDesigner = host.GetDesigner(site1.Component)
If designer IsNot Nothing AndAlso Not designer.Verbs.Contains(insPage) Then
designer.Verbs.Add(insPage)
End If
End If
End If
End If
Return site1
End Get
Set(ByVal value As ISite)
MyBase.Site = value
End Set
End Property
Protected Sub OnInsertPageClicked(ByVal sender As Object, ByVal e As EventArgs)
Dim site As ISite = MyBase.Site
If site IsNot Nothing AndAlso site.DesignMode Then
Dim container As IContainer = site.Container
If container IsNot Nothing Then
Dim btn As New TabStripButton()
container.Add(btn)
btn.Text = btn.Name
End If
End If
End Sub
''' <summary>
''' Gets custom renderer for TabStrip. Set operation has no effect
''' </summary>
Public Shadows Property Renderer() As ToolStripRenderer
Get
Return myRenderer
End Get
Set(ByVal value As ToolStripRenderer)
MyBase.Renderer = myRenderer
End Set
End Property
''' <summary>
''' Gets or sets layout style for TabStrip control
''' </summary>
Public Shadows Property LayoutStyle() As ToolStripLayoutStyle
Get
Return MyBase.LayoutStyle
End Get
Set(ByVal value As ToolStripLayoutStyle)
Select Case value
Case ToolStripLayoutStyle.StackWithOverflow, ToolStripLayoutStyle.HorizontalStackWithOverflow, ToolStripLayoutStyle.VerticalStackWithOverflow
MyBase.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow
Exit Select
Case ToolStripLayoutStyle.Table
MyBase.LayoutStyle = ToolStripLayoutStyle.Table
Exit Select
Case ToolStripLayoutStyle.Flow
MyBase.LayoutStyle = ToolStripLayoutStyle.Flow
Exit Select
Case Else
MyBase.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow
Exit Select
End Select
End Set
End Property
''' <summary>
'''
''' </summary>
<Obsolete("Use RenderStyle instead")> _
<Browsable(False)> _
Public Shadows Property RenderMode() As ToolStripRenderMode
Get
Return MyBase.RenderMode
End Get
Set(ByVal value As ToolStripRenderMode)
RenderStyle = value
End Set
End Property
''' <summary>
''' Gets or sets render style for TabStrip, use it instead of
''' </summary>
<Category("Appearance")> _
<Description("Gets or sets render style for TabStrip. You should use this property instead of RenderMode.")> _
Public Property RenderStyle() As ToolStripRenderMode
Get
Return myRenderer.RenderMode
End Get
Set(ByVal value As ToolStripRenderMode)
myRenderer.RenderMode = value
Me.Invalidate()
End Set
End Property
Protected Overrides ReadOnly Property DefaultPadding() As Padding
Get
Return Padding.Empty
End Get
End Property
<Browsable(False)> _
Public Shadows Property Padding() As Padding
Get
Return DefaultPadding
End Get
Set(ByVal value As Padding)
End Set
End Property
''' <summary>
''' Gets or sets if control should use system visual styles for painting items
''' </summary>
<Category("Appearance")> _
<Description("Specifies if TabStrip should use system visual styles for painting items")> _
Public Property UseVisualStyles() As Boolean
Get
Return myRenderer.UseVS
End Get
Set(ByVal value As Boolean)
myRenderer.UseVS = value
Me.Invalidate()
End Set
End Property
''' <summary>
''' Gets or sets if TabButtons should be drawn flipped
''' </summary>
<Category("Appearance")> _
<Description("Specifies if TabButtons should be drawn flipped (for right- and bottom-aligned TabStrips)")> _
Public Property FlipButtons() As Boolean
Get
Return myRenderer.Mirrored
End Get
Set(ByVal value As Boolean)
myRenderer.Mirrored = value
Me.Invalidate()
End Set
End Property
''' <summary>
''' Gets or sets currently selected tab
''' </summary>
Public Property SelectedTab() As TabStripButton
Get
Return mySelTab
End Get
Set(ByVal value As TabStripButton)
If value Is Nothing Then
Return
End If
If mySelTab Is value Then
Return
End If
If value.Owner IsNot Me Then
Throw New ArgumentException("Cannot select TabButtons that do not belong to this TabStrip")
End If
OnItemClicked(New ToolStripItemClickedEventArgs(value))
End Set
End Property
Public Event SelectedTabChanged As EventHandler(Of SelectedTabChangedEventArgs)
Protected Sub OnTabSelected(ByVal tab As TabStripButton)
Me.Invalidate()
If Not Me.Created Then Exit Sub
RaiseEvent SelectedTabChanged(Me, New SelectedTabChangedEventArgs(tab))
End Sub
Protected Overrides Sub OnItemAdded(ByVal e As ToolStripItemEventArgs)
MyBase.OnItemAdded(e)
If TypeOf e.Item Is TabStripButton Then
SelectedTab = DirectCast(e.Item, TabStripButton)
End If
End Sub
Protected Overrides Sub OnItemClicked(ByVal e As ToolStripItemClickedEventArgs)
Dim clickedBtn As TabStripButton = TryCast(e.ClickedItem, TabStripButton)
If clickedBtn IsNot Nothing Then
If clickedBtn.IsOnOverflow Then
Me.Items.Insert(0, clickedBtn)
End If
Me.SuspendLayout()
mySelTab = clickedBtn
Me.ResumeLayout()
OnTabSelected(clickedBtn)
End If
MyBase.OnItemClicked(e)
End Sub
End Class
''' <summary>
''' Represents a renderer class for TabStrip control
''' </summary>
Friend Class TabStripRenderer
Inherits ToolStripRenderer
Private Const selOffset As Integer = 2
Private currentRenderer As ToolStripRenderer = Nothing
Private m_renderMode As ToolStripRenderMode = ToolStripRenderMode.[Custom]
Private m_mirrored As Boolean = False
Private m_useVS As Boolean = Application.RenderWithVisualStyles
''' <summary>
''' Gets or sets render mode for this renderer
''' </summary>
Public Property RenderMode() As ToolStripRenderMode
Get
Return m_renderMode
End Get
Set(ByVal value As ToolStripRenderMode)
m_renderMode = value
Select Case m_renderMode
Case ToolStripRenderMode.Professional
currentRenderer = New ToolStripProfessionalRenderer()
Exit Select
Case ToolStripRenderMode.System
currentRenderer = New ToolStripSystemRenderer()
Exit Select
Case Else
currentRenderer = Nothing
Exit Select
End Select
End Set
End Property
''' <summary>
''' Gets or sets whether to mirror background
''' </summary>
''' <remarks>Use false for left and top positions, true for right and bottom</remarks>
Public Property Mirrored() As Boolean
Get
Return m_mirrored
End Get
Set(ByVal value As Boolean)
m_mirrored = value
End Set
End Property
''' <summary>
''' Returns if visual styles should be applied for drawing
''' </summary>
Public Property UseVS() As Boolean
Get
Return m_useVS
End Get
Set(ByVal value As Boolean)
If value AndAlso Not Application.RenderWithVisualStyles Then
Return
End If
m_useVS = value
End Set
End Property
Protected Overrides Sub Initialize(ByVal ts As ToolStrip)
MyBase.Initialize(ts)
End Sub
Protected Overrides Sub OnRenderToolStripBorder(ByVal e As ToolStripRenderEventArgs)
Dim c As Color = SystemColors.AppWorkspace
If UseVS Then
Dim rndr As New VisualStyleRenderer(VisualStyleElement.Tab.Pane.Normal)
c = rndr.GetColor(ColorProperty.BorderColorHint)
End If
Using p As New Pen(c)
Using p2 As New Pen(e.BackColor)
Dim r As Rectangle = e.ToolStrip.Bounds
Dim x1 As Integer = IIf((Mirrored), 0, r.Width - 1 - e.ToolStrip.Padding.Horizontal)
Dim y1 As Integer = IIf((Mirrored), 0, r.Height - 1)
If e.ToolStrip.Orientation = Orientation.Horizontal Then
e.Graphics.DrawLine(p, 0, y1, r.Width, y1)
Else
e.Graphics.DrawLine(p, x1, 0, x1, r.Height)
If Not Mirrored Then
For i As Integer = x1 + 1 To r.Width - 1
e.Graphics.DrawLine(p2, i, 0, i, r.Height)
Next
End If
End If
For Each x As ToolStripItem In e.ToolStrip.Items
If x.IsOnOverflow Then
Continue For
End If
Dim btn As TabStripButton = TryCast(x, TabStripButton)
If btn Is Nothing Then
Continue For
End If
Dim rc As Rectangle = btn.Bounds
Dim x2 As Integer = IIf((Mirrored), rc.Left, rc.Right)
Dim y2 As Integer = IIf((Mirrored), rc.Top, rc.Bottom - 1)
Dim addXY As Integer = IIf((Mirrored), 0, 1)
If e.ToolStrip.Orientation = Orientation.Horizontal Then
e.Graphics.DrawLine(p, rc.Left, y2, rc.Right, y2)
If btn.Checked Then
e.Graphics.DrawLine(p2, rc.Left + 2 - addXY, y2, rc.Right - 2 - addXY, y2)
End If
Else
e.Graphics.DrawLine(p, x2, rc.Top, x2, rc.Bottom)
If btn.Checked Then
e.Graphics.DrawLine(p2, x2, rc.Top + 2 - addXY, x2, rc.Bottom - 2 - addXY)
End If
End If
Next
End Using
End Using
End Sub
Protected Overrides Sub OnRenderToolStripBackground(ByVal e As ToolStripRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawToolStripBackground(e)
Else
MyBase.OnRenderToolStripBackground(e)
End If
End Sub
Protected Overrides Sub OnRenderButtonBackground(ByVal e As ToolStripItemRenderEventArgs)
Dim g As Graphics = e.Graphics
Dim tabs As TabStrip = TryCast(e.ToolStrip, TabStrip)
Dim tab As TabStripButton = TryCast(e.Item, TabStripButton)
If tabs Is Nothing OrElse tab Is Nothing Then
If currentRenderer IsNot Nothing Then
currentRenderer.DrawButtonBackground(e)
Else
MyBase.OnRenderButtonBackground(e)
End If
Return
End If
Dim selected As Boolean = tab.Checked
Dim hovered As Boolean = tab.Selected
Dim top As Integer = 0
Dim left As Integer = 0
Dim width As Integer = tab.Bounds.Width - 1
Dim height As Integer = tab.Bounds.Height - 1
Dim drawBorder As Rectangle
If UseVS Then
If tabs.Orientation = Orientation.Horizontal Then
If Not selected Then
top = selOffset
height -= (selOffset - 1)
Else
top = 1
End If
drawBorder = New Rectangle(0, 0, width, height)
Else
If Not selected Then
left = selOffset
width -= (selOffset - 1)
Else
left = 1
End If
drawBorder = New Rectangle(0, 0, height, width)
End If
Using b As New Bitmap(drawBorder.Width, drawBorder.Height)
Dim el As VisualStyleElement = VisualStyleElement.Tab.TabItem.Normal
If selected Then
el = VisualStyleElement.Tab.TabItem.Pressed
End If
If hovered Then
el = VisualStyleElement.Tab.TabItem.Hot
End If
If Not tab.Enabled Then
el = VisualStyleElement.Tab.TabItem.Disabled
End If
If Not selected OrElse hovered Then
drawBorder.Width += 1
Else
drawBorder.Height += 1
End If
Using gr As Graphics = Graphics.FromImage(b)
Dim rndr As New VisualStyleRenderer(el)
rndr.DrawBackground(gr, drawBorder)
If tabs.Orientation = Orientation.Vertical Then
If Mirrored Then
b.RotateFlip(RotateFlipType.Rotate270FlipXY)
Else
b.RotateFlip(RotateFlipType.Rotate270FlipNone)
End If
Else
If Mirrored Then
b.RotateFlip(RotateFlipType.RotateNoneFlipY)
End If
End If
If Mirrored Then
left = tab.Bounds.Width - b.Width - left
top = tab.Bounds.Height - b.Height - top
End If
g.DrawImage(b, left, top)
End Using
End Using
Else
If tabs.Orientation = Orientation.Horizontal Then
If Not selected Then
top = selOffset
height -= (selOffset - 1)
Else
top = 1
End If
If Mirrored Then
left = 1
top = 0
Else
top += 1
End If
width -= 1
Else
If Not selected Then
left = selOffset
width -= 1
Else
left = 1
End If
If Mirrored Then
left = 0
top = 1
End If
End If
height -= 1
drawBorder = New Rectangle(left, top, width, height)
Using gp As New GraphicsPath()
If Mirrored AndAlso tabs.Orientation = Orientation.Horizontal Then
gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Left, drawBorder.Bottom - 2)
gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90)
gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right - 2, drawBorder.Bottom)
gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90)
gp.AddLine(drawBorder.Right, drawBorder.Bottom - 2, drawBorder.Right, drawBorder.Top)
ElseIf Not Mirrored AndAlso tabs.Orientation = Orientation.Horizontal Then
gp.AddLine(drawBorder.Left, drawBorder.Bottom, drawBorder.Left, drawBorder.Top + 2)
gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90)
gp.AddLine(drawBorder.Left + 2, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top)
gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90)
gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom)
ElseIf Mirrored AndAlso tabs.Orientation = Orientation.Vertical Then
gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top)
gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90)
gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom - 2)
gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90)
gp.AddLine(drawBorder.Right - 2, drawBorder.Bottom, drawBorder.Left, drawBorder.Bottom)
Else
gp.AddLine(drawBorder.Right, drawBorder.Top, drawBorder.Left + 2, drawBorder.Top)
gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90)
gp.AddLine(drawBorder.Left, drawBorder.Top + 2, drawBorder.Left, drawBorder.Bottom - 2)
gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90)
gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right, drawBorder.Bottom)
End If
If selected OrElse hovered Then
Dim fill As Color = IIf((hovered), Color.WhiteSmoke, Color.White)
If m_renderMode = ToolStripRenderMode.Professional Then
fill = IIf((hovered), ProfessionalColors.ButtonCheckedGradientBegin, ProfessionalColors.ButtonCheckedGradientEnd)
Using br As New LinearGradientBrush(tab.ContentRectangle, fill, ProfessionalColors.ButtonCheckedGradientMiddle, LinearGradientMode.Vertical)
g.FillPath(br, gp)
End Using
Else
Using br As New SolidBrush(fill)
g.FillPath(br, gp)
End Using
End If
End If
Dim color1 As Color = IIf((selected), ControlPaint.Dark(SystemColors.AppWorkspace), SystemColors.AppWorkspace)
Using p As New Pen(color1)
g.DrawPath(p, gp)
End Using
End Using
End If
End Sub
Protected Overrides Sub OnRenderItemImage(ByVal e As ToolStripItemImageRenderEventArgs)
Dim rc As Rectangle = e.ImageRectangle
Dim btn As TabStripButton = TryCast(e.Item, TabStripButton)
If btn IsNot Nothing Then
Dim delta As Integer = (IIf((Mirrored), -1, 1)) * (IIf((btn.Checked), 1, selOffset))
If e.ToolStrip.Orientation = Orientation.Horizontal Then
rc.Offset(IIf((Mirrored), 2, 1), delta + (IIf((Mirrored), 1, 0)))
Else
rc.Offset(delta + 2, 0)
End If
End If
Dim x As New ToolStripItemImageRenderEventArgs(e.Graphics, e.Item, e.Image, rc)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawItemImage(x)
Else
MyBase.OnRenderItemImage(x)
End If
End Sub
Protected Overrides Sub OnRenderItemText(ByVal e As ToolStripItemTextRenderEventArgs)
Dim rc As Rectangle = e.TextRectangle
Dim btn As TabStripButton = TryCast(e.Item, TabStripButton)
Dim c As Color = e.TextColor
Dim f As Font = e.TextFont
If btn IsNot Nothing Then
Dim delta As Integer = (IIf((Mirrored), -1, 1)) * (IIf((btn.Checked), 1, selOffset))
If e.ToolStrip.Orientation = Orientation.Horizontal Then
rc.Offset(IIf((Mirrored), 2, 1), delta + (IIf((Mirrored), 1, -1)))
Else
rc.Offset(delta + 2, 0)
End If
If btn.Selected Then
c = btn.HotTextColor
ElseIf btn.Checked Then
c = btn.SelectedTextColor
End If
If btn.Checked Then
f = btn.SelectedFont
End If
End If
Dim x As New ToolStripItemTextRenderEventArgs(e.Graphics, e.Item, e.Text, rc, c, f, _
e.TextFormat)
x.TextDirection = e.TextDirection
If currentRenderer IsNot Nothing Then
currentRenderer.DrawItemText(x)
Else
MyBase.OnRenderItemText(x)
End If
End Sub
Protected Overrides Sub OnRenderArrow(ByVal e As ToolStripArrowRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawArrow(e)
Else
MyBase.OnRenderArrow(e)
End If
End Sub
Protected Overrides Sub OnRenderDropDownButtonBackground(ByVal e As ToolStripItemRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawDropDownButtonBackground(e)
Else
MyBase.OnRenderDropDownButtonBackground(e)
End If
End Sub
Protected Overrides Sub OnRenderGrip(ByVal e As ToolStripGripRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawGrip(e)
Else
MyBase.OnRenderGrip(e)
End If
End Sub
Protected Overrides Sub OnRenderImageMargin(ByVal e As ToolStripRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawImageMargin(e)
Else
MyBase.OnRenderImageMargin(e)
End If
End Sub
Protected Overrides Sub OnRenderItemBackground(ByVal e As ToolStripItemRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawItemBackground(e)
Else
MyBase.OnRenderItemBackground(e)
End If
End Sub
Protected Overrides Sub OnRenderItemCheck(ByVal e As ToolStripItemImageRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawItemCheck(e)
Else
MyBase.OnRenderItemCheck(e)
End If
End Sub
Protected Overrides Sub OnRenderLabelBackground(ByVal e As ToolStripItemRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawLabelBackground(e)
Else
MyBase.OnRenderLabelBackground(e)
End If
End Sub
Protected Overrides Sub OnRenderMenuItemBackground(ByVal e As ToolStripItemRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawMenuItemBackground(e)
Else
MyBase.OnRenderMenuItemBackground(e)
End If
End Sub
Protected Overrides Sub OnRenderOverflowButtonBackground(ByVal e As ToolStripItemRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawOverflowButtonBackground(e)
Else
MyBase.OnRenderOverflowButtonBackground(e)
End If
End Sub
Protected Overrides Sub OnRenderSeparator(ByVal e As ToolStripSeparatorRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawSeparator(e)
Else
MyBase.OnRenderSeparator(e)
End If
End Sub
Protected Overrides Sub OnRenderSplitButtonBackground(ByVal e As ToolStripItemRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawSplitButton(e)
Else
MyBase.OnRenderSplitButtonBackground(e)
End If
End Sub
Protected Overrides Sub OnRenderStatusStripSizingGrip(ByVal e As ToolStripRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawStatusStripSizingGrip(e)
Else
MyBase.OnRenderStatusStripSizingGrip(e)
End If
End Sub
Protected Overrides Sub OnRenderToolStripContentPanelBackground(ByVal e As ToolStripContentPanelRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawToolStripContentPanelBackground(e)
Else
MyBase.OnRenderToolStripContentPanelBackground(e)
End If
End Sub
Protected Overrides Sub OnRenderToolStripPanelBackground(ByVal e As ToolStripPanelRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawToolStripPanelBackground(e)
Else
MyBase.OnRenderToolStripPanelBackground(e)
End If
End Sub
Protected Overrides Sub OnRenderToolStripStatusLabelBackground(ByVal e As ToolStripItemRenderEventArgs)
If currentRenderer IsNot Nothing Then
currentRenderer.DrawToolStripStatusLabelBackground(e)
Else
MyBase.OnRenderToolStripStatusLabelBackground(e)
End If
End Sub
End Class
''' <summary>
''' Represents a TabButton for TabStrip control
''' </summary>
<ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip)> _
Public Class TabStripButton
Inherits ToolStripButton
Public Sub New()
MyBase.New()
InitButton()
End Sub
Public Sub New(ByVal image As Image)
MyBase.New(image)
InitButton()
End Sub
Public Sub New(ByVal text As String)
MyBase.New(text)
InitButton()
End Sub
Public Sub New(ByVal text As String, ByVal image As Image)
MyBase.New(text, image)
InitButton()
End Sub
Public Sub New(ByVal Text As String, ByVal Image As Image, ByVal Handler As EventHandler)
MyBase.New(Text, Image, Handler)
InitButton()
End Sub
Public Sub New(ByVal Text As String, ByVal Image As Image, ByVal Handler As EventHandler, ByVal name As String)
MyBase.New(Text, Image, Handler, name)
InitButton()
End Sub
Private Sub InitButton()
m_SelectedFont = Me.Font
End Sub
Public Overrides Function GetPreferredSize(ByVal constrainingSize As Size) As Size
Dim sz As Size = MyBase.GetPreferredSize(constrainingSize)
If Me.Owner IsNot Nothing AndAlso Me.Owner.Orientation = Orientation.Vertical Then
sz.Width += 3
sz.Height += 10
End If
Return sz
End Function
Protected Overrides ReadOnly Property DefaultMargin() As Padding
Get
Return New Padding(0)
End Get
End Property
<Browsable(False)> _
Public Shadows Property Margin() As Padding
Get
Return MyBase.Margin
End Get
Set(ByVal value As Padding)
End Set
End Property
<Browsable(False)> _
Public Shadows Property Padding() As Padding
Get
Return MyBase.Padding
End Get
Set(ByVal value As Padding)
End Set
End Property
Private m_HotTextColor As Color = Control.DefaultForeColor
<Category("Appearance")> _
<Description("Text color when TabButton is highlighted")> _
Public Property HotTextColor() As Color
Get
Return m_HotTextColor
End Get
Set(ByVal value As Color)
m_HotTextColor = value
End Set
End Property
Private m_SelectedTextColor As Color = Control.DefaultForeColor
<Category("Appearance")> _
<Description("Text color when TabButton is selected")> _
Public Property SelectedTextColor() As Color
Get
Return m_SelectedTextColor
End Get
Set(ByVal value As Color)
m_SelectedTextColor = value
End Set
End Property
Private m_SelectedFont As Font
<Category("Appearance")> _
<Description("Font when TabButton is selected")> _
Public Property SelectedFont() As Font
Get
Return IIf((m_SelectedFont Is Nothing), Me.Font, m_SelectedFont)
End Get
Set(ByVal value As Font)
m_SelectedFont = value
End Set
End Property
<Browsable(False)> _
<DefaultValue(False)> _
Public Shadows Property Checked() As Boolean
Get
Return IsSelected
End Get
Set(ByVal value As Boolean)
End Set
End Property
''' <summary>
''' Gets or sets if this TabButton is currently selected
''' </summary>
<Browsable(False)> _
Public Property IsSelected() As Boolean
Get
Dim owner__1 As TabStrip = TryCast(Owner, TabStrip)
If owner__1 IsNot Nothing Then
Return (Me Is owner__1.SelectedTab)
End If
Return False
End Get
Set(ByVal value As Boolean)
If value = False Then
Return
End If
Dim owner__1 As TabStrip = TryCast(Owner, TabStrip)
If owner__1 Is Nothing Then
Return
End If
owner__1.SelectedTab = Me
End Set
End Property
Protected Overrides Sub OnOwnerChanged(ByVal e As EventArgs)
If Owner IsNot Nothing AndAlso Not (TypeOf Owner Is TabStrip) Then
Throw New Exception("Cannot add TabStripButton to " & Owner.[GetType]().Name)
End If
MyBase.OnOwnerChanged(e)
End Sub
End Class
End Namespace