This code is derived from:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2005JUL.1033/cpref/html/frlrfSystemWindowsFormsMenuItemClassOwnerDrawTopic .htm
The sample works as presented but does not contain a click event. Here is
my abridged version of the code. In this code, if I use MenuItem2.OwnerDraw
= False, it behaves as expected: no ownerdraw and when clicked, I see the
message.
If MenuItem2.OwnerDraw = True, I see the colored text but when I click,
nothing happens. How can I have colored text that responds to the click
event?
--------------------------------------------------------------------------------------
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
MenuItem2 = New MenuItem("Custom Menu Item")
MenuItem2.OwnerDraw = True
AddHandler MenuItem2.DrawItem, New DrawItemEventHandler(AddressOf
DrawCustomMenuItem)
AddHandler MenuItem2.Click, AddressOf MenuItem2Click
MainMenu1 = New MainMenu(New MenuItem() {MenuItem2})
Me.Menu = Me.MainMenu1
components = New System.ComponentModel.Container
Me.Text = "Form2"
End Sub
#End Region
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Private Sub DrawCustomMenuItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs)
Dim customItem As MenuItem = CType(sender, MenuItem)
Dim aBrush As System.Drawing.Brush =
System.Drawing.Brushes.DarkMagenta
e.Graphics.DrawString(customItem.Text, e.Font, aBrush, e.Bounds.X,
e.Bounds.Y)
End Sub
Private Sub MenuItem2Click(ByVal sender As Object, ByVal e As
System.EventArgs)
MsgBox("This is a test")
End Sub
End Class