I have an owner-drawn menu by subclassing MenuItem and it works fine, except that the grey border and drop shadow of the original MenuItem still appears, how can I get rid of this?
Here's the code I have, using VB.NET:
Any help would be much appreciated!
Here's the code I have, using VB.NET:
Code:
Public Class ColourMenuItem : Inherits MenuItem
Private _ForeColour As Color
Private _BackColour As Color
Private _HoverColour As Color
Private _Font As New Font("Verdana", 8)
Public Sub New(ByVal text As String, ByVal ForeColour As Color, ByVal BackColour As Color, ByVal HoverColour As Color, ByVal onClick As EventHandler)
MyBase.New(text, onClick)
OwnerDraw = True
_ForeColour = ForeColour
_BackColour = BackColour
_HoverColour = HoverColour
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As DrawItemEventArgs)
MyBase.OnDrawItem(e)
Dim br As Brush
Dim rcBk As Rectangle = e.Bounds
If CBool(e.State And DrawItemState.Selected) Then
br = New SolidBrush(_HoverColour)
Else
br = New SolidBrush(_BackColour)
End If
e.Graphics.FillRectangle(br, rcBk)
Dim sf As New StringFormat()
sf.HotkeyPrefix = Drawing.Text.HotkeyPrefix.Show
br = New SolidBrush(_ForeColour)
e.Graphics.DrawString(Text, _Font, br, e.Bounds.Left + 2, e.Bounds.Top + 2, sf)
End Sub
Protected Overrides Sub OnMeasureItem(ByVal e As MeasureItemEventArgs)
Dim sf As New StringFormat()
sf.HotkeyPrefix = Drawing.Text.HotkeyPrefix.Show
MyBase.OnMeasureItem(e)
e.ItemHeight = CInt(e.Graphics.MeasureString(Text, _Font, 10000, sf).Height) + 4
e.ItemWidth = CInt(e.Graphics.MeasureString(Text, _Font, 10000, sf).Width) + 10
End Sub
End Class
Any help would be much appreciated!