Public Class cMenuBar
Public Sub New()
InitializeComponent()
Dim renderer As New cToolStripRenderer
Me.Renderer = renderer
End Sub
Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaintBackground(e)
Dim Rect As New Rectangle(0, 0, Me.Width, Me.Height)
Dim bgGradient As New LinearGradientBrush(Rect, Color.FromArgb(255, 235, 233, 237), Color.FromArgb(255, 251, 250, 251), LinearGradientMode.Horizontal)
e.Graphics.FillRectangle(bgGradient, Rect)
End Sub
End Class
Friend Class cToolStripRenderer
Inherits ToolStripRenderer
'The brush that paints the background of
'the GridStrip control.
Private backgroundBrush As Brush = Nothing
'This method initializes an individual ToolStripButton
'control. It copies a subimage from the ToolStripRenderer's
'main image, according to the position and size of
'the ToolStripButton.
Protected Overrides Sub InitializeItem(ByVal item As System.Windows.Forms.ToolStripItem)
MyBase.InitializeItem(item)
Try
Dim ms As MenuStrip = item.Owner
'The empty cell does not receive a subimage.
If (TypeOf (item) Is ToolStripButton) Then
'Copy the subimage from the appropriate
'part of the main image.
Dim subImage As Bitmap = bmp.Clone(item.Bounds, Imaging.PixelFormat.Undefined)
'assign the subimage to the ToolStripButton
'control's Image property.
item.Image = subImage
End If
Catch ex As Exception
End Try
End Sub
'This method renders the MenuStrip control's background.
Protected Overrides Sub OnRenderToolStripBackground(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
MyBase.OnRenderToolStripBackground(e)
Dim rect As New Rectangle(2, 0, 28, e.ToolStrip.Size.Height)
Dim b As Brush = New LinearGradientBrush(rect, Color.FromArgb(255, 235, 233, 237), Color.FromArgb(255, 183, 183, 184), LinearGradientMode.Vertical, True)
Dim rec As New Rectangle(29, 0, 1, e.ToolStrip.Size.Height)
Dim b1 As Brush = Brushes.Black
Dim rec1 As New Rectangle(0, 0, 2, e.ToolStrip.Size.Height)
Dim b2 As Brush = New LinearGradientBrush(rec1, Color.FromArgb(255, 235, 234, 238), Color.FromArgb(255, 235, 234, 238), LinearGradientMode.Horizontal, True)
Dim r As New Rectangle(30, 0, e.ToolStrip.Size.Width, e.ToolStrip.Size.Height)
'This late initialization is a workaround. The gradient depends on the bounds of the MenuStrip control. The bounds
'are dependent on the layout engine, which hasn't fully performed layout by the time the Initialize method runs.
If Me.backgroundBrush Is Nothing Then
Me.backgroundBrush = New LinearGradientBrush(r, Color.FromArgb(255, 222, 221, 225), Color.FromArgb(255, 251, 250, 251), LinearGradientMode.Horizontal, True)
End If
'Paint the MenuStrip control's background
e.Graphics.FillRectangle(b2, rec1)
e.Graphics.FillRectangle(b, rect)
e.Graphics.FillRectangle(b1, rec)
e.Graphics.FillRectangle(Me.backgroundBrush, r)
End Sub
End Class