Hi all

I am writing a class to control the aesthetics of a .Net MainMenu object in VB.

I have all of the child menu items displaying correctly, with icons, colours, etc; but I am having trouble with the main "parent" menuitems. When I respond to the DrawItem and MeasureItem events of the parent menuitems, the "active" area that you can click on with the mouse becomes very small - about 1/4" wide on my screen. How do I control this?


If it helps, here is the code I am using to draw the CHILD menuitems. For the parent menu items, I would just like to the ability to control font and icons - I don't need the other colours etc.

Any pointers are appreciated!

VB Code:
  1. Private Sub _DrawMenuItem(ByVal sender As Object, ByRef e As System.Windows.Forms.DrawItemEventArgs, ByVal theIcon As String)
  2.         Dim MenuFont As Font
  3.         Dim FillColor As Color
  4.         Dim BorderColor As Color
  5.         Dim FontColor As Color
  6.  
  7.         Dim myRectangle As New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.X + 24, e.Bounds.Height)
  8.         Dim myLinearGradientBrush As New LinearGradientBrush(myRectangle, Color.FromArgb(249, 249, 255), Color.FromArgb(165, 163, 189), LinearGradientMode.Horizontal)
  9.         MenuFont = New System.Drawing.Font("Verdana", 8)
  10.  
  11.         With e.Graphics
  12.             If e.State = (DrawItemState.Selected Or DrawItemState.NoAccelerator) Or e.State = DrawItemState.Selected Then 'hovering
  13.                 RaiseEvent ShowHandCursor()
  14.                 FillColor = Color.FromArgb(195, 211, 233)
  15.                 BorderColor = Color.FromArgb(133, 175, 232)
  16.                 FontColor = Color.FromArgb(0, 70, 165)
  17.                 .FillRectangle(New SolidBrush(FillColor), e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height - 1)
  18.                 .DrawRectangle(New Pen(BorderColor), e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width - 2, e.Bounds.Height - 1)
  19.                 .DrawString(sender.Text, MenuFont, New SolidBrush(FontColor), 30, e.Bounds.Y + 3)
  20.             Else 'not hovering
  21.                 RaiseEvent ShowDefaultCursor()
  22.                 FillColor = Color.White
  23.                 FontColor = Color.Black
  24.                 .FillRectangle(New SolidBrush(FillColor), e.Bounds.X + 24, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
  25.                 .FillRectangle(myLinearGradientBrush, e.Bounds.X, e.Bounds.Y, e.Bounds.X + 24, e.Bounds.Height)
  26.                 .DrawString(sender.Text, MenuFont, New SolidBrush(FontColor), 30, e.Bounds.Y + 3)
  27.             End If
  28.  
  29.             If Not theIcon Is Nothing Then
  30.                 .DrawIcon(New Icon(New Icon(theIcon), 16, 16), e.Bounds.X + 4, e.Bounds.Y + 1)
  31.             End If
  32.  
  33.         End With
  34.     End Sub