A
ahmeddc
Guest
Hello
I found this control and want to add a property to change the background color of a particular entry
1-DESIGN PROPERTIES COLOR TOPGRADIENT
2-DESIGN PROPERTIES COLOR BOTTOMGRADIENT
Public MustInherit Class xColorTable
Public MustOverride ReadOnly Property TextColor As Color
Public MustOverride ReadOnly Property Background As Color
Public MustOverride ReadOnly Property SelectionBorder As Color
Public MustOverride ReadOnly Property SelectionTopGradient As Color
Public MustOverride ReadOnly Property SelectionMidGradient As Color
Public MustOverride ReadOnly Property SelectionBottomGradient As Color
Public MustOverride ReadOnly Property PressedBackground As Color
Public MustOverride ReadOnly Property CheckedBackground As Color
Public MustOverride ReadOnly Property CheckedSelectedBackground As Color
Public MustOverride ReadOnly Property DropdownBorder As Color
Public MustOverride ReadOnly Property Arrow As Color
Public MustOverride ReadOnly Property OverflowBackground As Color
End Class
Public MustInherit Class ColorTable
Public MustOverride ReadOnly Property CommonColorTable As xColorTable
Public MustOverride ReadOnly Property BackgroundTopGradient As Color
Public MustOverride ReadOnly Property BackgroundBottomGradient As Color
Public MustOverride ReadOnly Property DroppedDownItemBackground As Color
Public MustOverride ReadOnly Property DropdownTopGradient As Color
Public MustOverride ReadOnly Property DropdownBottomGradient As Color
Public MustOverride ReadOnly Property Separator As Color
Public MustOverride ReadOnly Property ImageMargin As Color
End Class
Public Class MSColorTable
Inherits ColorTable
Private _CommonColorTable As xColorTable
Private _BaseColor As Color = Color.FromArgb(60, 70, 73)
<Category("Colors")> _
Public Property BaseColor As Color
Get
Return _BaseColor
End Get
Set(ByVal value As Color)
_BaseColor = value
End Set
End Property
Public Sub New()
_CommonColorTable = New DefaultCColorTable()
End Sub
Public Overrides ReadOnly Property CommonColorTable As xColorTable
Get
Return _CommonColorTable
End Get
End Property
Public Overrides ReadOnly Property BackgroundTopGradient As System.Drawing.Color
Get
Return Color.FromArgb(246, 246, 246)
End Get
End Property
Public Overrides ReadOnly Property BackgroundBottomGradient As System.Drawing.Color
Get
Return Color.FromArgb(226, 226, 226)
End Get
End Property
Public Overrides ReadOnly Property DropdownTopGradient As System.Drawing.Color
Get
Return Color.FromArgb(246, 246, 246)
End Get
End Property
Public Overrides ReadOnly Property DropdownBottomGradient As System.Drawing.Color
Get
Return Color.FromArgb(246, 246, 246)
End Get
End Property
Public Overrides ReadOnly Property DroppedDownItemBackground As System.Drawing.Color
Get
Return Color.FromArgb(240, 240, 240)
End Get
End Property
Public Overrides ReadOnly Property Separator As System.Drawing.Color
Get
Return Color.FromArgb(190, 195, 203)
End Get
End Property
Public Overrides ReadOnly Property ImageMargin As System.Drawing.Color
Get
Return Color.FromArgb(240, 240, 240)
End Get
End Property
End Class
Public Class DefaultCColorTable
Inherits xColorTable
Public Overrides ReadOnly Property CheckedBackground As System.Drawing.Color
Get
Return Color.FromArgb(230, 230, 230)
End Get
End Property
Public Overrides ReadOnly Property CheckedSelectedBackground As System.Drawing.Color
Get
Return Color.FromArgb(230, 230, 230)
End Get
End Property
Public Overrides ReadOnly Property SelectionBorder As System.Drawing.Color
Get
Return Color.FromArgb(180, 180, 180)
End Get
End Property
Public Overrides ReadOnly Property SelectionTopGradient As System.Drawing.Color
Get
Return Color.FromArgb(240, 240, 240)
End Get
End Property
Public Overrides ReadOnly Property SelectionMidGradient As System.Drawing.Color
Get
Return Color.FromArgb(235, 235, 235)
End Get
End Property
Public Overrides ReadOnly Property SelectionBottomGradient As System.Drawing.Color
Get
Return Color.FromArgb(230, 230, 230)
End Get
End Property
Public Overrides ReadOnly Property PressedBackground As System.Drawing.Color
Get
Return Color.FromArgb(232, 232, 232)
End Get
End Property
Public Overrides ReadOnly Property TextColor As System.Drawing.Color
Get
Return Color.FromArgb(80, 80, 80)
End Get
End Property
Public Overrides ReadOnly Property Background As System.Drawing.Color
Get
Return Color.FromArgb(188, 199, 216)
End Get
End Property
Public Overrides ReadOnly Property DropdownBorder As System.Drawing.Color
Get
Return Color.LightGray
End Get
End Property
Public Overrides ReadOnly Property Arrow As System.Drawing.Color
Get
Return Color.Black
End Get
End Property
Public Overrides ReadOnly Property OverflowBackground As System.Drawing.Color
Get
Return Color.FromArgb(213, 220, 232)
End Get
End Property
End Class
#End Region
#Region " Renderer "
Public Class ControlRenderer
Inherits ToolStripProfessionalRenderer
Public Sub New()
Me.New(New MSColorTable())
End Sub
Public Sub New(ByVal ColorTable As ColorTable)
Me.ColorTable = ColorTable
End Sub
Private _ColorTable As ColorTable
Public Overloads Property ColorTable() As ColorTable
Get
If _ColorTable Is Nothing Then
_ColorTable = New MSColorTable()
End If
Return _ColorTable
End Get
Set(ByVal value As ColorTable)
_ColorTable = value
End Set
End Property
Protected Overrides Sub OnRenderToolStripBackground(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
MyBase.OnRenderToolStripBackground(e)
' Menu strip bar gradient
Using LGB As New LinearGradientBrush(e.AffectedBounds, Me.ColorTable.BackgroundTopGradient, Me.ColorTable.BackgroundBottomGradient, LinearGradientMode.Vertical)
e.Graphics.FillRectangle(LGB, e.AffectedBounds)
End Using
End Sub
Protected Overrides Sub OnRenderToolStripBorder(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
If e.ToolStrip.Parent Is Nothing Then
' Draw border around the menu drop-down
Dim Rect As New Rectangle(0, 0, e.ToolStrip.Width - 1, e.ToolStrip.Height - 1)
Using P1 As New Pen(Me.ColorTable.CommonColorTable.DropdownBorder)
e.Graphics.DrawRectangle(P1, Rect)
End Using
' Fill the gap between menu drop-down and owner item
Using B1 As New SolidBrush(Me.ColorTable.DroppedDownItemBackground)
e.Graphics.FillRectangle(B1, e.ConnectedArea)
End Using
End If
End Sub
Protected Overrides Sub OnRenderMenuItemBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
If e.Item.Enabled Then
If e.Item.Selected Then
If Not e.Item.IsOnDropDown Then
Dim SelRect As New Rectangle(0, 0, e.Item.Width - 1, e.Item.Height - 1)
RectDrawing.DrawSelection(e.Graphics, Me.ColorTable.CommonColorTable, SelRect)
Else
Dim SelRect As New Rectangle(2, 0, e.Item.Width - 4, e.Item.Height - 1)
RectDrawing.DrawSelection(e.Graphics, Me.ColorTable.CommonColorTable, SelRect)
End If
End If
If CType(e.Item, ToolStripMenuItem).DropDown.Visible AndAlso Not e.Item.IsOnDropDown Then
Dim BorderRect As New Rectangle(0, 0, e.Item.Width - 1, e.Item.Height)
' Fill the background
Dim BackgroundRect As New Rectangle(1, 1, e.Item.Width - 2, e.Item.Height + 2)
Using B1 As New SolidBrush(Me.ColorTable.DroppedDownItemBackground)
e.Graphics.FillRectangle(B1, BackgroundRect)
End Using
' Draw border
Using P1 As New Pen(Me.ColorTable.CommonColorTable.DropdownBorder)
RectDrawing.DrawRoundedRectangle(e.Graphics, P1, BorderRect.X, BorderRect.Y, BorderRect.Width, BorderRect.Height, 2)
End Using
End If
e.Item.ForeColor = Me.ColorTable.CommonColorTable.TextColor
End If
End Sub
Protected Overrides Sub OnRenderItemText(ByVal e As System.Windows.Forms.ToolStripItemTextRenderEventArgs)
e.TextColor = Me.ColorTable.CommonColorTable.TextColor
MyBase.OnRenderItemText(e)
End Sub
Protected Overrides Sub OnRenderItemCheck(ByVal e As System.Windows.Forms.ToolStripItemImageRenderEventArgs)
MyBase.OnRenderItemCheck(e)
Dim rect As New Rectangle(3, 1, e.Item.Height - 3, e.Item.Height - 3)
Dim c As Color
If e.Item.Selected Then
c = Me.ColorTable.CommonColorTable.CheckedSelectedBackground
Else
c = Me.ColorTable.CommonColorTable.CheckedBackground
End If
Using b As New SolidBrush(c)
e.Graphics.FillRectangle(b, rect)
End Using
Using p As New Pen(Me.ColorTable.CommonColorTable.SelectionBorder)
e.Graphics.DrawRectangle(p, rect)
End Using
e.Graphics.DrawString("ü", New Font("Wingdings", 13, FontStyle.Regular), Brushes.Black, New Point(4, 2))
End Sub
Protected Overrides Sub OnRenderSeparator(ByVal e As System.Windows.Forms.ToolStripSeparatorRenderEventArgs)
MyBase.OnRenderSeparator(e)
Dim PT1 As Integer = 28
Dim PT2 As Integer = e.Item.Width
Dim Y As Integer = 3
Using P1 As New Pen(Me.ColorTable.Separator)
e.Graphics.DrawLine(P1, PT1, Y, PT2, Y)
End Using
End Sub
Protected Overrides Sub OnRenderImageMargin(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
MyBase.OnRenderImageMargin(e)
Dim BackgroundRect As New Rectangle(0, -1, e.ToolStrip.Width, e.ToolStrip.Height + 1)
Using LGB As New LinearGradientBrush(BackgroundRect,
Me.ColorTable.DropdownTopGradient,
Me.ColorTable.DropdownBottomGradient,
LinearGradientMode.Vertical)
e.Graphics.FillRectangle(LGB, BackgroundRect)
End Using
Using B1 As New SolidBrush(Me.ColorTable.ImageMargin)
e.Graphics.FillRectangle(B1, e.AffectedBounds)
End Using
End Sub
Protected Overrides Sub OnRenderButtonBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
Dim rect As New Rectangle(0, 0, e.Item.Width - 1, e.Item.Height - 1)
Dim checked As Boolean = CType(e.Item, ToolStripButton).Checked
Dim drawBorder As Boolean = False
If checked Then
drawBorder = True
If e.Item.Selected AndAlso Not e.Item.Pressed Then
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.CheckedSelectedBackground)
e.Graphics.FillRectangle(b, rect)
End Using
Else
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.CheckedBackground)
e.Graphics.FillRectangle(b, rect)
End Using
End If
Else
If e.Item.Pressed Then
drawBorder = True
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.PressedBackground)
e.Graphics.FillRectangle(b, rect)
End Using
ElseIf e.Item.Selected Then
drawBorder = True
RectDrawing.DrawSelection(e.Graphics, Me.ColorTable.CommonColorTable, rect)
End If
End If
If drawBorder Then
Using p As New Pen(Me.ColorTable.CommonColorTable.SelectionBorder)
e.Graphics.DrawRectangle(p, rect)
End Using
End If
End Sub
Protected Overrides Sub OnRenderDropDownButtonBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
Dim rect As New Rectangle(0, 0, e.Item.Width - 1, e.Item.Height - 1)
Dim drawBorder As Boolean = False
If e.Item.Pressed Then
drawBorder = True
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.PressedBackground)
e.Graphics.FillRectangle(b, rect)
End Using
ElseIf e.Item.Selected Then
drawBorder = True
RectDrawing.DrawSelection(e.Graphics, Me.ColorTable.CommonColorTable, rect)
End If
If drawBorder Then
Using p As New Pen(Me.ColorTable.CommonColorTable.SelectionBorder)
e.Graphics.DrawRectangle(p, rect)
End Using
End If
End Sub
Protected Overrides Sub OnRenderSplitButtonBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
MyBase.OnRenderSplitButtonBackground(e)
Dim drawBorder As Boolean = False
Dim drawSeparator As Boolean = True
Dim item = DirectCast(e.Item, ToolStripSplitButton)
Dim btnRect As New Rectangle(0, 0, item.ButtonBounds.Width - 1, item.ButtonBounds.Height - 1)
Dim borderRect As New Rectangle(0, 0, item.Bounds.Width - 1, item.Bounds.Height - 1)
If item.DropDownButtonPressed Then
drawBorder = True
drawSeparator = False
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.PressedBackground)
e.Graphics.FillRectangle(b, borderRect)
End Using
ElseIf item.DropDownButtonSelected Then
drawBorder = True
RectDrawing.DrawSelection(e.Graphics, Me.ColorTable.CommonColorTable, borderRect)
End If
If item.ButtonPressed Then
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.PressedBackground)
e.Graphics.FillRectangle(b, btnRect)
End Using
End If
If drawBorder Then
Using p As New Pen(Me.ColorTable.CommonColorTable.SelectionBorder)
e.Graphics.DrawRectangle(p, borderRect)
If drawSeparator Then e.Graphics.DrawRectangle(p, btnRect)
End Using
Me.DrawCustomArrow(e.Graphics, item)
End If
End Sub
Private Sub DrawCustomArrow(ByVal g As Graphics, ByVal item As ToolStripSplitButton)
Dim dropWidth As Integer = item.DropDownButtonBounds.Width - 1
Dim dropHeight As Integer = item.DropDownButtonBounds.Height - 1
Dim triangleWidth As Single = dropWidth / 2.0F + 1
Dim triangleLeft As Single = item.DropDownButtonBounds.Left + (dropWidth - triangleWidth) / 2.0F
Dim triangleHeight As Single = triangleWidth / 2.0F
Dim triangleTop As Single = item.DropDownButtonBounds.Top + (dropHeight - triangleHeight) / 2.0F + 1
Dim arrowRect As New RectangleF(triangleLeft, triangleTop, triangleWidth, triangleHeight)
Me.DrawCustomArrow(g, item, Rectangle.Round(arrowRect))
End Sub
Private Sub DrawCustomArrow(ByVal g As Graphics, ByVal item As ToolStripItem, ByVal rect As Rectangle)
Dim arrowEventArgs As New ToolStripArrowRenderEventArgs(g, _
item, _
rect, _
Me.ColorTable.CommonColorTable.Arrow, _
ArrowDirection.Down)
MyBase.OnRenderArrow(arrowEventArgs)
End Sub
Protected Overrides Sub OnRenderOverflowButtonBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
Dim rect, rectEnd As Rectangle
rect = New Rectangle(0, 0, e.Item.Width - 1, e.Item.Height - 2)
rectEnd = New Rectangle(rect.X - 5, rect.Y, rect.Width - 5, rect.Height)
If e.Item.Pressed Then
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.PressedBackground)
e.Graphics.FillRectangle(b, rect)
End Using
ElseIf e.Item.Selected Then
RectDrawing.DrawSelection(e.Graphics, Me.ColorTable.CommonColorTable, rect)
Else
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.OverflowBackground)
e.Graphics.FillRectangle(b, rect)
End Using
End If
Using P1 As New Pen(Me.ColorTable.CommonColorTable.Background)
RectDrawing.DrawRoundedRectangle(e.Graphics, P1, rectEnd.X, rectEnd.Y, rectEnd.Width, rectEnd.Height, 3)
End Using
' Icon
Dim w As Integer = rect.Width - 1
Dim h As Integer = rect.Height - 1
Dim triangleWidth As Single = w / 2.0F + 1
Dim triangleLeft As Single = rect.Left + (w - triangleWidth) / 2.0F + 3
Dim triangleHeight As Single = triangleWidth / 2.0F
Dim triangleTop As Single = rect.Top + (h - triangleHeight) / 2.0F + 7
Dim arrowRect As New RectangleF(triangleLeft, triangleTop, triangleWidth, triangleHeight)
Me.DrawCustomArrow(e.Graphics, e.Item, Rectangle.Round(arrowRect))
Using p As New Pen(Me.ColorTable.CommonColorTable.Arrow)
e.Graphics.DrawLine(p, triangleLeft + 2, triangleTop - 2, triangleLeft + triangleWidth - 2, triangleTop - 2)
End Using
End Sub
End Class
#End Region
#Region " Drawing "
Public Class RectDrawing
Public Shared Sub DrawSelection(ByVal G As Graphics, _
ByVal ColorTable As xColorTable, _
ByVal Rect As Rectangle)
Dim TopRect As Rectangle
Dim BottomRect As Rectangle
Dim FillRect As New Rectangle(Rect.X + 1, Rect.Y + 1, Rect.Width - 1, Rect.Height - 1)
TopRect = FillRect
TopRect.Height -= CInt(TopRect.Height / 2)
BottomRect = New Rectangle(TopRect.X, TopRect.Bottom, TopRect.Width, FillRect.Height - TopRect.Height)
' Top gradient
Using LGB As New LinearGradientBrush(TopRect, ColorTable.SelectionTopGradient, ColorTable.SelectionMidGradient, LinearGradientMode.Vertical)
G.FillRectangle(LGB, TopRect)
End Using
' Bottom
Using B1 As New SolidBrush(ColorTable.SelectionBottomGradient)
G.FillRectangle(B1, BottomRect)
End Using
' Border
Using P1 As New Pen(ColorTable.SelectionBorder)
RectDrawing.DrawRoundedRectangle(G, P1, Rect.X, Rect.Y, Rect.Width, Rect.Height, 2)
End Using
End Sub
Public Shared Sub DrawRoundedRectangle(ByVal G As Graphics, _
ByVal P As Pen, _
ByVal X As Single, _
ByVal Y As Single, _
ByVal W As Single, _
ByVal H As Single, _
ByVal Rad As Single)
Using gp As New GraphicsPath()
gp.AddLine(X + Rad, Y, X + W - (Rad * 2), Y)
gp.AddArc(X + W - (Rad * 2), Y, Rad * 2, Rad * 2, 270, 90)
gp.AddLine(X + W, Y + Rad, X + W, Y + H - (Rad * 2))
gp.AddArc(X + W - (Rad * 2), Y + H - (Rad * 2), Rad * 2, Rad * 2, 0, 90)
gp.AddLine(X + W - (Rad * 2), Y + H, X + Rad, Y + H)
gp.AddArc(X, Y + H - (Rad * 2), Rad * 2, Rad * 2, 90, 90)
gp.AddLine(X, Y + H - (Rad * 2), X, Y + Rad)
gp.AddArc(X, Y, Rad * 2, Rad * 2, 180, 90)
gp.CloseFigure()
G.SmoothingMode = SmoothingMode.AntiAlias
G.DrawPath(P, gp)
G.SmoothingMode = SmoothingMode.Default
End Using
End Sub
End Class
#End Region
#End Region
Public Class iTalk_MenuStrip
Inherits MenuStrip
Public Sub New()
Me.Renderer = New ControlRenderer()
End Sub
Public Overloads Property Renderer() As ControlRenderer
Get
Return DirectCast(MyBase.Renderer, ControlRenderer)
End Get
Set(ByVal value As ControlRenderer)
MyBase.Renderer = value
End Set
End Property
End Class
Continue reading...
I found this control and want to add a property to change the background color of a particular entry
1-DESIGN PROPERTIES COLOR TOPGRADIENT
2-DESIGN PROPERTIES COLOR BOTTOMGRADIENT
Public MustInherit Class xColorTable
Public MustOverride ReadOnly Property TextColor As Color
Public MustOverride ReadOnly Property Background As Color
Public MustOverride ReadOnly Property SelectionBorder As Color
Public MustOverride ReadOnly Property SelectionTopGradient As Color
Public MustOverride ReadOnly Property SelectionMidGradient As Color
Public MustOverride ReadOnly Property SelectionBottomGradient As Color
Public MustOverride ReadOnly Property PressedBackground As Color
Public MustOverride ReadOnly Property CheckedBackground As Color
Public MustOverride ReadOnly Property CheckedSelectedBackground As Color
Public MustOverride ReadOnly Property DropdownBorder As Color
Public MustOverride ReadOnly Property Arrow As Color
Public MustOverride ReadOnly Property OverflowBackground As Color
End Class
Public MustInherit Class ColorTable
Public MustOverride ReadOnly Property CommonColorTable As xColorTable
Public MustOverride ReadOnly Property BackgroundTopGradient As Color
Public MustOverride ReadOnly Property BackgroundBottomGradient As Color
Public MustOverride ReadOnly Property DroppedDownItemBackground As Color
Public MustOverride ReadOnly Property DropdownTopGradient As Color
Public MustOverride ReadOnly Property DropdownBottomGradient As Color
Public MustOverride ReadOnly Property Separator As Color
Public MustOverride ReadOnly Property ImageMargin As Color
End Class
Public Class MSColorTable
Inherits ColorTable
Private _CommonColorTable As xColorTable
Private _BaseColor As Color = Color.FromArgb(60, 70, 73)
<Category("Colors")> _
Public Property BaseColor As Color
Get
Return _BaseColor
End Get
Set(ByVal value As Color)
_BaseColor = value
End Set
End Property
Public Sub New()
_CommonColorTable = New DefaultCColorTable()
End Sub
Public Overrides ReadOnly Property CommonColorTable As xColorTable
Get
Return _CommonColorTable
End Get
End Property
Public Overrides ReadOnly Property BackgroundTopGradient As System.Drawing.Color
Get
Return Color.FromArgb(246, 246, 246)
End Get
End Property
Public Overrides ReadOnly Property BackgroundBottomGradient As System.Drawing.Color
Get
Return Color.FromArgb(226, 226, 226)
End Get
End Property
Public Overrides ReadOnly Property DropdownTopGradient As System.Drawing.Color
Get
Return Color.FromArgb(246, 246, 246)
End Get
End Property
Public Overrides ReadOnly Property DropdownBottomGradient As System.Drawing.Color
Get
Return Color.FromArgb(246, 246, 246)
End Get
End Property
Public Overrides ReadOnly Property DroppedDownItemBackground As System.Drawing.Color
Get
Return Color.FromArgb(240, 240, 240)
End Get
End Property
Public Overrides ReadOnly Property Separator As System.Drawing.Color
Get
Return Color.FromArgb(190, 195, 203)
End Get
End Property
Public Overrides ReadOnly Property ImageMargin As System.Drawing.Color
Get
Return Color.FromArgb(240, 240, 240)
End Get
End Property
End Class
Public Class DefaultCColorTable
Inherits xColorTable
Public Overrides ReadOnly Property CheckedBackground As System.Drawing.Color
Get
Return Color.FromArgb(230, 230, 230)
End Get
End Property
Public Overrides ReadOnly Property CheckedSelectedBackground As System.Drawing.Color
Get
Return Color.FromArgb(230, 230, 230)
End Get
End Property
Public Overrides ReadOnly Property SelectionBorder As System.Drawing.Color
Get
Return Color.FromArgb(180, 180, 180)
End Get
End Property
Public Overrides ReadOnly Property SelectionTopGradient As System.Drawing.Color
Get
Return Color.FromArgb(240, 240, 240)
End Get
End Property
Public Overrides ReadOnly Property SelectionMidGradient As System.Drawing.Color
Get
Return Color.FromArgb(235, 235, 235)
End Get
End Property
Public Overrides ReadOnly Property SelectionBottomGradient As System.Drawing.Color
Get
Return Color.FromArgb(230, 230, 230)
End Get
End Property
Public Overrides ReadOnly Property PressedBackground As System.Drawing.Color
Get
Return Color.FromArgb(232, 232, 232)
End Get
End Property
Public Overrides ReadOnly Property TextColor As System.Drawing.Color
Get
Return Color.FromArgb(80, 80, 80)
End Get
End Property
Public Overrides ReadOnly Property Background As System.Drawing.Color
Get
Return Color.FromArgb(188, 199, 216)
End Get
End Property
Public Overrides ReadOnly Property DropdownBorder As System.Drawing.Color
Get
Return Color.LightGray
End Get
End Property
Public Overrides ReadOnly Property Arrow As System.Drawing.Color
Get
Return Color.Black
End Get
End Property
Public Overrides ReadOnly Property OverflowBackground As System.Drawing.Color
Get
Return Color.FromArgb(213, 220, 232)
End Get
End Property
End Class
#End Region
#Region " Renderer "
Public Class ControlRenderer
Inherits ToolStripProfessionalRenderer
Public Sub New()
Me.New(New MSColorTable())
End Sub
Public Sub New(ByVal ColorTable As ColorTable)
Me.ColorTable = ColorTable
End Sub
Private _ColorTable As ColorTable
Public Overloads Property ColorTable() As ColorTable
Get
If _ColorTable Is Nothing Then
_ColorTable = New MSColorTable()
End If
Return _ColorTable
End Get
Set(ByVal value As ColorTable)
_ColorTable = value
End Set
End Property
Protected Overrides Sub OnRenderToolStripBackground(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
MyBase.OnRenderToolStripBackground(e)
' Menu strip bar gradient
Using LGB As New LinearGradientBrush(e.AffectedBounds, Me.ColorTable.BackgroundTopGradient, Me.ColorTable.BackgroundBottomGradient, LinearGradientMode.Vertical)
e.Graphics.FillRectangle(LGB, e.AffectedBounds)
End Using
End Sub
Protected Overrides Sub OnRenderToolStripBorder(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
If e.ToolStrip.Parent Is Nothing Then
' Draw border around the menu drop-down
Dim Rect As New Rectangle(0, 0, e.ToolStrip.Width - 1, e.ToolStrip.Height - 1)
Using P1 As New Pen(Me.ColorTable.CommonColorTable.DropdownBorder)
e.Graphics.DrawRectangle(P1, Rect)
End Using
' Fill the gap between menu drop-down and owner item
Using B1 As New SolidBrush(Me.ColorTable.DroppedDownItemBackground)
e.Graphics.FillRectangle(B1, e.ConnectedArea)
End Using
End If
End Sub
Protected Overrides Sub OnRenderMenuItemBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
If e.Item.Enabled Then
If e.Item.Selected Then
If Not e.Item.IsOnDropDown Then
Dim SelRect As New Rectangle(0, 0, e.Item.Width - 1, e.Item.Height - 1)
RectDrawing.DrawSelection(e.Graphics, Me.ColorTable.CommonColorTable, SelRect)
Else
Dim SelRect As New Rectangle(2, 0, e.Item.Width - 4, e.Item.Height - 1)
RectDrawing.DrawSelection(e.Graphics, Me.ColorTable.CommonColorTable, SelRect)
End If
End If
If CType(e.Item, ToolStripMenuItem).DropDown.Visible AndAlso Not e.Item.IsOnDropDown Then
Dim BorderRect As New Rectangle(0, 0, e.Item.Width - 1, e.Item.Height)
' Fill the background
Dim BackgroundRect As New Rectangle(1, 1, e.Item.Width - 2, e.Item.Height + 2)
Using B1 As New SolidBrush(Me.ColorTable.DroppedDownItemBackground)
e.Graphics.FillRectangle(B1, BackgroundRect)
End Using
' Draw border
Using P1 As New Pen(Me.ColorTable.CommonColorTable.DropdownBorder)
RectDrawing.DrawRoundedRectangle(e.Graphics, P1, BorderRect.X, BorderRect.Y, BorderRect.Width, BorderRect.Height, 2)
End Using
End If
e.Item.ForeColor = Me.ColorTable.CommonColorTable.TextColor
End If
End Sub
Protected Overrides Sub OnRenderItemText(ByVal e As System.Windows.Forms.ToolStripItemTextRenderEventArgs)
e.TextColor = Me.ColorTable.CommonColorTable.TextColor
MyBase.OnRenderItemText(e)
End Sub
Protected Overrides Sub OnRenderItemCheck(ByVal e As System.Windows.Forms.ToolStripItemImageRenderEventArgs)
MyBase.OnRenderItemCheck(e)
Dim rect As New Rectangle(3, 1, e.Item.Height - 3, e.Item.Height - 3)
Dim c As Color
If e.Item.Selected Then
c = Me.ColorTable.CommonColorTable.CheckedSelectedBackground
Else
c = Me.ColorTable.CommonColorTable.CheckedBackground
End If
Using b As New SolidBrush(c)
e.Graphics.FillRectangle(b, rect)
End Using
Using p As New Pen(Me.ColorTable.CommonColorTable.SelectionBorder)
e.Graphics.DrawRectangle(p, rect)
End Using
e.Graphics.DrawString("ü", New Font("Wingdings", 13, FontStyle.Regular), Brushes.Black, New Point(4, 2))
End Sub
Protected Overrides Sub OnRenderSeparator(ByVal e As System.Windows.Forms.ToolStripSeparatorRenderEventArgs)
MyBase.OnRenderSeparator(e)
Dim PT1 As Integer = 28
Dim PT2 As Integer = e.Item.Width
Dim Y As Integer = 3
Using P1 As New Pen(Me.ColorTable.Separator)
e.Graphics.DrawLine(P1, PT1, Y, PT2, Y)
End Using
End Sub
Protected Overrides Sub OnRenderImageMargin(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
MyBase.OnRenderImageMargin(e)
Dim BackgroundRect As New Rectangle(0, -1, e.ToolStrip.Width, e.ToolStrip.Height + 1)
Using LGB As New LinearGradientBrush(BackgroundRect,
Me.ColorTable.DropdownTopGradient,
Me.ColorTable.DropdownBottomGradient,
LinearGradientMode.Vertical)
e.Graphics.FillRectangle(LGB, BackgroundRect)
End Using
Using B1 As New SolidBrush(Me.ColorTable.ImageMargin)
e.Graphics.FillRectangle(B1, e.AffectedBounds)
End Using
End Sub
Protected Overrides Sub OnRenderButtonBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
Dim rect As New Rectangle(0, 0, e.Item.Width - 1, e.Item.Height - 1)
Dim checked As Boolean = CType(e.Item, ToolStripButton).Checked
Dim drawBorder As Boolean = False
If checked Then
drawBorder = True
If e.Item.Selected AndAlso Not e.Item.Pressed Then
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.CheckedSelectedBackground)
e.Graphics.FillRectangle(b, rect)
End Using
Else
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.CheckedBackground)
e.Graphics.FillRectangle(b, rect)
End Using
End If
Else
If e.Item.Pressed Then
drawBorder = True
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.PressedBackground)
e.Graphics.FillRectangle(b, rect)
End Using
ElseIf e.Item.Selected Then
drawBorder = True
RectDrawing.DrawSelection(e.Graphics, Me.ColorTable.CommonColorTable, rect)
End If
End If
If drawBorder Then
Using p As New Pen(Me.ColorTable.CommonColorTable.SelectionBorder)
e.Graphics.DrawRectangle(p, rect)
End Using
End If
End Sub
Protected Overrides Sub OnRenderDropDownButtonBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
Dim rect As New Rectangle(0, 0, e.Item.Width - 1, e.Item.Height - 1)
Dim drawBorder As Boolean = False
If e.Item.Pressed Then
drawBorder = True
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.PressedBackground)
e.Graphics.FillRectangle(b, rect)
End Using
ElseIf e.Item.Selected Then
drawBorder = True
RectDrawing.DrawSelection(e.Graphics, Me.ColorTable.CommonColorTable, rect)
End If
If drawBorder Then
Using p As New Pen(Me.ColorTable.CommonColorTable.SelectionBorder)
e.Graphics.DrawRectangle(p, rect)
End Using
End If
End Sub
Protected Overrides Sub OnRenderSplitButtonBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
MyBase.OnRenderSplitButtonBackground(e)
Dim drawBorder As Boolean = False
Dim drawSeparator As Boolean = True
Dim item = DirectCast(e.Item, ToolStripSplitButton)
Dim btnRect As New Rectangle(0, 0, item.ButtonBounds.Width - 1, item.ButtonBounds.Height - 1)
Dim borderRect As New Rectangle(0, 0, item.Bounds.Width - 1, item.Bounds.Height - 1)
If item.DropDownButtonPressed Then
drawBorder = True
drawSeparator = False
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.PressedBackground)
e.Graphics.FillRectangle(b, borderRect)
End Using
ElseIf item.DropDownButtonSelected Then
drawBorder = True
RectDrawing.DrawSelection(e.Graphics, Me.ColorTable.CommonColorTable, borderRect)
End If
If item.ButtonPressed Then
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.PressedBackground)
e.Graphics.FillRectangle(b, btnRect)
End Using
End If
If drawBorder Then
Using p As New Pen(Me.ColorTable.CommonColorTable.SelectionBorder)
e.Graphics.DrawRectangle(p, borderRect)
If drawSeparator Then e.Graphics.DrawRectangle(p, btnRect)
End Using
Me.DrawCustomArrow(e.Graphics, item)
End If
End Sub
Private Sub DrawCustomArrow(ByVal g As Graphics, ByVal item As ToolStripSplitButton)
Dim dropWidth As Integer = item.DropDownButtonBounds.Width - 1
Dim dropHeight As Integer = item.DropDownButtonBounds.Height - 1
Dim triangleWidth As Single = dropWidth / 2.0F + 1
Dim triangleLeft As Single = item.DropDownButtonBounds.Left + (dropWidth - triangleWidth) / 2.0F
Dim triangleHeight As Single = triangleWidth / 2.0F
Dim triangleTop As Single = item.DropDownButtonBounds.Top + (dropHeight - triangleHeight) / 2.0F + 1
Dim arrowRect As New RectangleF(triangleLeft, triangleTop, triangleWidth, triangleHeight)
Me.DrawCustomArrow(g, item, Rectangle.Round(arrowRect))
End Sub
Private Sub DrawCustomArrow(ByVal g As Graphics, ByVal item As ToolStripItem, ByVal rect As Rectangle)
Dim arrowEventArgs As New ToolStripArrowRenderEventArgs(g, _
item, _
rect, _
Me.ColorTable.CommonColorTable.Arrow, _
ArrowDirection.Down)
MyBase.OnRenderArrow(arrowEventArgs)
End Sub
Protected Overrides Sub OnRenderOverflowButtonBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
Dim rect, rectEnd As Rectangle
rect = New Rectangle(0, 0, e.Item.Width - 1, e.Item.Height - 2)
rectEnd = New Rectangle(rect.X - 5, rect.Y, rect.Width - 5, rect.Height)
If e.Item.Pressed Then
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.PressedBackground)
e.Graphics.FillRectangle(b, rect)
End Using
ElseIf e.Item.Selected Then
RectDrawing.DrawSelection(e.Graphics, Me.ColorTable.CommonColorTable, rect)
Else
Using b As New SolidBrush(Me.ColorTable.CommonColorTable.OverflowBackground)
e.Graphics.FillRectangle(b, rect)
End Using
End If
Using P1 As New Pen(Me.ColorTable.CommonColorTable.Background)
RectDrawing.DrawRoundedRectangle(e.Graphics, P1, rectEnd.X, rectEnd.Y, rectEnd.Width, rectEnd.Height, 3)
End Using
' Icon
Dim w As Integer = rect.Width - 1
Dim h As Integer = rect.Height - 1
Dim triangleWidth As Single = w / 2.0F + 1
Dim triangleLeft As Single = rect.Left + (w - triangleWidth) / 2.0F + 3
Dim triangleHeight As Single = triangleWidth / 2.0F
Dim triangleTop As Single = rect.Top + (h - triangleHeight) / 2.0F + 7
Dim arrowRect As New RectangleF(triangleLeft, triangleTop, triangleWidth, triangleHeight)
Me.DrawCustomArrow(e.Graphics, e.Item, Rectangle.Round(arrowRect))
Using p As New Pen(Me.ColorTable.CommonColorTable.Arrow)
e.Graphics.DrawLine(p, triangleLeft + 2, triangleTop - 2, triangleLeft + triangleWidth - 2, triangleTop - 2)
End Using
End Sub
End Class
#End Region
#Region " Drawing "
Public Class RectDrawing
Public Shared Sub DrawSelection(ByVal G As Graphics, _
ByVal ColorTable As xColorTable, _
ByVal Rect As Rectangle)
Dim TopRect As Rectangle
Dim BottomRect As Rectangle
Dim FillRect As New Rectangle(Rect.X + 1, Rect.Y + 1, Rect.Width - 1, Rect.Height - 1)
TopRect = FillRect
TopRect.Height -= CInt(TopRect.Height / 2)
BottomRect = New Rectangle(TopRect.X, TopRect.Bottom, TopRect.Width, FillRect.Height - TopRect.Height)
' Top gradient
Using LGB As New LinearGradientBrush(TopRect, ColorTable.SelectionTopGradient, ColorTable.SelectionMidGradient, LinearGradientMode.Vertical)
G.FillRectangle(LGB, TopRect)
End Using
' Bottom
Using B1 As New SolidBrush(ColorTable.SelectionBottomGradient)
G.FillRectangle(B1, BottomRect)
End Using
' Border
Using P1 As New Pen(ColorTable.SelectionBorder)
RectDrawing.DrawRoundedRectangle(G, P1, Rect.X, Rect.Y, Rect.Width, Rect.Height, 2)
End Using
End Sub
Public Shared Sub DrawRoundedRectangle(ByVal G As Graphics, _
ByVal P As Pen, _
ByVal X As Single, _
ByVal Y As Single, _
ByVal W As Single, _
ByVal H As Single, _
ByVal Rad As Single)
Using gp As New GraphicsPath()
gp.AddLine(X + Rad, Y, X + W - (Rad * 2), Y)
gp.AddArc(X + W - (Rad * 2), Y, Rad * 2, Rad * 2, 270, 90)
gp.AddLine(X + W, Y + Rad, X + W, Y + H - (Rad * 2))
gp.AddArc(X + W - (Rad * 2), Y + H - (Rad * 2), Rad * 2, Rad * 2, 0, 90)
gp.AddLine(X + W - (Rad * 2), Y + H, X + Rad, Y + H)
gp.AddArc(X, Y + H - (Rad * 2), Rad * 2, Rad * 2, 90, 90)
gp.AddLine(X, Y + H - (Rad * 2), X, Y + Rad)
gp.AddArc(X, Y, Rad * 2, Rad * 2, 180, 90)
gp.CloseFigure()
G.SmoothingMode = SmoothingMode.AntiAlias
G.DrawPath(P, gp)
G.SmoothingMode = SmoothingMode.Default
End Using
End Sub
End Class
#End Region
#End Region
Public Class iTalk_MenuStrip
Inherits MenuStrip
Public Sub New()
Me.Renderer = New ControlRenderer()
End Sub
Public Overloads Property Renderer() As ControlRenderer
Get
Return DirectCast(MyBase.Renderer, ControlRenderer)
End Get
Set(ByVal value As ControlRenderer)
MyBase.Renderer = value
End Set
End Property
End Class
Continue reading...