Public Class EmoticonMenuItem
Inherits MenuItem
Private Const ICON_WIDTH As Integer = 19
Private Const ICON_HEIGHT As Integer = 19
Private Const ICON_MARGIN As Integer = 4
Private _backgroundColor As Color
Private _selectionColor As Color
Private _selectionBorderColor As Color
Private _image As Image
Public Sub New(img As Image)
Me.New()
Me._image = _image
End Sub
Public Sub New()
MyBase.OwnerDraw = True
Me._backgroundColor = SystemColors.ControlLightLight
Me._selectionColor = Color.FromArgb(50, 0, 0, 150)
Me._selectionBorderColor = SystemColors.Highlight
End Sub
Public Property Image() As Image
Get
Return Me._image
End Get
Set(value As Image)
Me._image = value
End Set
End Property
Protected Overrides Sub OnDrawItem(e As DrawItemEventArgs)
'MyBase.OnDrawItem(e)
Dim g As Graphics = e.Graphics
Dim bounds As Rectangle = e.Bounds
Dim selected As Boolean = (e.State And DrawItemState.Selected) <> DrawItemState.None
Me.DrawBackground(g, bounds, selected)
If Me._image IsNot Nothing Then
Dim x As Integer = CInt(bounds.X + (bounds.Width - ICON_WIDTH) / 2)
Dim y As Integer = CInt(bounds.Y + (bounds.Height - ICON_HEIGHT) / 2)
g.DrawImage(Me._image, x, y)
End If
End Sub
Protected Overrides Sub OnMeasureItem(e As MeasureItemEventArgs)
'MyBase.OnMeasureItem(e)
e.ItemHeight = 17
e.ItemWidth = 23
End Sub
Private Sub DrawBackground(g As Graphics, bounds As Rectangle, selected As Boolean)
If selected Then
g.FillRectangle(New SolidBrush(Me._selectionColor), bounds)
g.DrawRectangle(New Pen(Me._selectionBorderColor), bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1)
Else
g.FillRectangle(New SolidBrush(Me._backgroundColor), bounds)
End If
End Sub
End Class