Home All Groups Group Topic Archive Search About

ownerdraw menu, help appreciated

Author
14 Apr 2005 2:21 PM
Peter Proost
Hi, I've got the following ownerdraw menu:

drag a mainmenu on a form and add some menuitems to it, set all the
menuitems to ownerdraw = true

and for every menuitem add this code (replace nothing with an ico if you
want to show an icon in the menu)
also add a module and copy paste the code at the bottom of the message.

Private Sub MenuItem1_DrawItem1(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DrawItemEventArgs) Handles MenuItem1.DrawItem
    DrawItems(e, MenuItem1, Nothing)
End Sub

Private Sub MenuItem1_MeasureItem1(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MeasureItemEventArgs) Handles MenuItem1.MeasureItem
    MeasureItems(e, MenuItem1)
End Sub

I've got it working ok, even a ____________ in a menu can be ownerdrawn, but
this afternoon I was playing with my code and I decided I wanted to add a
black border to the menuitems like VS2003 IDE menu's.
As you will see I was able to add the black borders, there's even a check to
see if the currently drawn menuitem is the last visible one and handles it.
But I can't draw the border on the actual menuitems' border, if anyone could
help me with this I would appreciate it very much, if not I'll just remove
the border part because I think it looks good even without the black borders
:-)

Thanks in advance greetz Peter


'Module om icoontjes aan een menu toe te voegen

Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Windows.Forms


Module IconsMenuMain

    Dim m_Font As New Font("Arial", 8)

    Sub MeasureItems(ByVal EvMeasureItem As
System.Windows.Forms.MeasureItemEventArgs, ByVal Mi _  As  MenuItem)
        Try
            Dim sf As StringFormat = New StringFormat()
            sf.HotkeyPrefix = HotkeyPrefix.Show
            sf.SetTabStops(60, New Single() {0})
            If Mi.Text <> "-" Then
                EvMeasureItem.ItemHeight = 22
            Else
                EvMeasureItem.ItemHeight = 7
            End If

            EvMeasureItem.ItemWidth =
CInt(EvMeasureItem.Graphics.MeasureString(GetRealText(Mi), _
                                                                 m_Font,
10000, sf).Width) + 30
            sf.Dispose()
            sf = Nothing
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
    Sub DrawItems(ByVal EvDrawItems As
System.Windows.Forms.DrawItemEventArgs, ByVal Mi As _
MenuItem, ByVal m_Icon As Icon)
        Try
            Dim blnNoMoreVisible As Boolean = False
            Dim br As Brush
            Dim br2 As Brush
            Dim fDisposeBrush As Boolean
            Dim rand As Pen

            Dim rcBk As Rectangle = EvDrawItems.Bounds
            rcBk.Height -= 2
            rcBk.Width -= 2
            If CBool(EvDrawItems.State And DrawItemState.Selected) Then
                br = New LinearGradientBrush(rcBk, Color.CadetBlue,
Color.LightBlue, 0)
                fDisposeBrush = True
                rand = New Pen(Color.DarkBlue, 1)
                EvDrawItems.Graphics.FillRectangle(br, rcBk)
                EvDrawItems.Graphics.DrawRectangle(rand, rcBk)

            Else
                br = SystemBrushes.Control
                br2 = New SolidBrush(Color.WhiteSmoke)
                rand = System.Drawing.SystemPens.Control
                EvDrawItems.Graphics.DrawRectangle(rand, rcBk)
                rcBk.X += 24
                rcBk.Width -= 23
                'rcBk.Y -= 1
                rcBk.Height += 2
                EvDrawItems.Graphics.FillRectangle(br2, rcBk)
                rcBk.X = 0
                rcBk.Width = 24
                EvDrawItems.Graphics.FillRectangle(br, rcBk)
                br2.Dispose()

            End If

            If fDisposeBrush Then br.Dispose()
            br = Nothing

            Dim sf As StringFormat = New StringFormat
            sf.HotkeyPrefix = HotkeyPrefix.Show
            sf.SetTabStops(60, New Single() {0})
            If Mi.Enabled Then
                br = New SolidBrush(EvDrawItems.ForeColor)
            Else
                br = New SolidBrush(Color.Gray)
            End If


            EvDrawItems.Graphics.DrawString(GetRealText(Mi), m_Font, br, _
                                            EvDrawItems.Bounds.Left + 25, _
                                            EvDrawItems.Bounds.Top + 2, sf)

            br.Dispose()
            br = Nothing
            sf.Dispose()
            sf = Nothing
            If Not m_Icon Is Nothing Then
                If Not Mi.Checked Then
                    EvDrawItems.Graphics.DrawIcon(m_Icon,
EvDrawItems.Bounds.Left + 2, _
                                                  EvDrawItems.Bounds.Top +
2)
                Else
                    EvDrawItems.Graphics.DrawIcon(m_Icon,
EvDrawItems.Bounds.Left + 2, _
                                                  EvDrawItems.Bounds.Top +
2)

                End If

            End If

            If Mi.Text = "-" Then
                EvDrawItems.Graphics.DrawLine(SystemPens.Control, 28,
EvDrawItems.Bounds.Top + 2, _ EvDrawItems.Bounds.Width,
EvDrawItems.Bounds.Top + 2)
            End If



            'Part for the border round all the menuitems
            If Mi.Index = 0 Then
                EvDrawItems.Graphics.DrawLine(Pens.Black, 1, 0,
EvDrawItems.Bounds.Width, 0)
                EvDrawItems.Graphics.DrawLine(Pens.Black, 1, 0, 1,
EvDrawItems.Bounds.Height)
                EvDrawItems.Graphics.DrawLine(Pens.Black,
EvDrawItems.Bounds.Width - 1, 0, _ EvDrawItems.Bounds.Width - 1,
EvDrawItems.Bounds.Height)
                If Mi.Index = Mi.Parent.MenuItems.Count - 1 Then
                    EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
EvDrawItems.Bounds.Top + _ EvDrawItems.Bounds.Height - 1,
EvDrawItems.Bounds.Width, EvDrawItems.Bounds.Top + _
EvDrawItems.Bounds.Height - 1)
                End If
            Else
                If Mi.Index < Mi.Parent.MenuItems.Count - 1 Then
                    EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
EvDrawItems.Bounds.Top, 1, _ EvDrawItems.Bounds.Top +
EvDrawItems.Bounds.Height)
                    EvDrawItems.Graphics.DrawLine(Pens.Black,
EvDrawItems.Bounds.Width - 1, EvDrawItems.Bounds.Top,
EvDrawItems.Bounds.Width - 1, EvDrawItems.Bounds.Top + _
EvDrawItems.Bounds.Height)
                    For i As Integer = Mi.Index + 1 To
Mi.Parent.MenuItems.Count - 1
                        If Mi.Parent.MenuItems(i).Visible = False Then
                            blnNoMoreVisible = True
                        Else
                            blnNoMoreVisible = False
                        End If
                    Next
                    If blnNoMoreVisible = True Then
                        EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
EvDrawItems.Bounds.Top + _  EvDrawItems.Bounds.Height - 1,
EvDrawItems.Bounds.Width, EvDrawItems.Bounds.Top + _
EvDrawItems.Bounds.Height - 1)
                        blnNoMoreVisible = False
                    End If
                End If
                If Mi.Index = Mi.Parent.MenuItems.Count - 1 Then
                    EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
EvDrawItems.Bounds.Top + _ EvDrawItems.Bounds.Height - 1,
EvDrawItems.Bounds.Width, EvDrawItems.Bounds.Top + _
EvDrawItems.Bounds.Height - 1)
                    EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
EvDrawItems.Bounds.Top, 1, _ EvDrawItems.Bounds.Top +
EvDrawItems.Bounds.Height)
                    EvDrawItems.Graphics.DrawLine(Pens.Black,
EvDrawItems.Bounds.Width - 1, _ EvDrawItems.Bounds.Top,
EvDrawItems.Bounds.Width - 1, EvDrawItems.Bounds.Top + _
EvDrawItems.Bounds.Height)
                End If
            End If
            'end of part for the border round the menuitems

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Function GetRealText(ByVal Mi As MenuItem) As String
        Try
            Dim s As String = Mi.Text
            If Mi.ShowShortcut And Mi.Shortcut <> Shortcut.None Then
                Dim k As Keys = CType(Mi.Shortcut, Keys)
                s = s & Convert.ToChar(9) & _

TypeDescriptor.GetConverter(GetType(Keys)).ConvertToString(k)
            End If
            Return s & StrDup(4, " ")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Function

End Module

Author
15 Apr 2005 2:55 AM
Ken Tucker [MVP]
Peter,

    You are drawing the border then painting over it.  Try this instead.

    Sub DrawItems(ByVal EvDrawItems As
System.Windows.Forms.DrawItemEventArgs, ByVal Mi As _
MenuItem, ByVal m_Icon As Icon)
        Try
            Dim blnNoMoreVisible As Boolean = False
            Dim br As Brush
            Dim br2 As Brush
            Dim fDisposeBrush As Boolean
            Dim rand As Pen

            Dim rcBk As Rectangle = EvDrawItems.Bounds
            rcBk.Height -= 2
            rcBk.Width -= 2
            If CBool(EvDrawItems.State And DrawItemState.Selected) Then
                br = New LinearGradientBrush(rcBk, Color.CadetBlue,
Color.LightBlue, 0)
                fDisposeBrush = True
                rand = New Pen(Color.DarkBlue, 1)
                EvDrawItems.Graphics.FillRectangle(br, rcBk)
                EvDrawItems.Graphics.DrawRectangle(rand, rcBk)

            Else
                br = SystemBrushes.Control
                br2 = New SolidBrush(Color.WhiteSmoke)
                rand = System.Drawing.SystemPens.Control
                rcBk.X += 24
                rcBk.Width -= 23
                'rcBk.Y -= 1
                rcBk.Height += 2
                EvDrawItems.Graphics.FillRectangle(br2, rcBk)
                rcBk.X = 0
                rcBk.Width = 24
                EvDrawItems.Graphics.FillRectangle(br, rcBk)
                EvDrawItems.Graphics.DrawRectangle(rand, rcBk)
                br2.Dispose()

            End If
etc.


Ken
----------------------
"Peter Proost" <pproost@nospam.hotmail.com> wrote in message
news:eTUkU1PQFHA.3416@TK2MSFTNGP10.phx.gbl...
Hi, I've got the following ownerdraw menu:

drag a mainmenu on a form and add some menuitems to it, set all the
menuitems to ownerdraw = true

and for every menuitem add this code (replace nothing with an ico if you
want to show an icon in the menu)
also add a module and copy paste the code at the bottom of the message.

Private Sub MenuItem1_DrawItem1(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DrawItemEventArgs) Handles MenuItem1.DrawItem
    DrawItems(e, MenuItem1, Nothing)
End Sub

Private Sub MenuItem1_MeasureItem1(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MeasureItemEventArgs) Handles MenuItem1.MeasureItem
    MeasureItems(e, MenuItem1)
End Sub

I've got it working ok, even a ____________ in a menu can be ownerdrawn, but
this afternoon I was playing with my code and I decided I wanted to add a
black border to the menuitems like VS2003 IDE menu's.
As you will see I was able to add the black borders, there's even a check to
see if the currently drawn menuitem is the last visible one and handles it.
But I can't draw the border on the actual menuitems' border, if anyone could
help me with this I would appreciate it very much, if not I'll just remove
the border part because I think it looks good even without the black borders
:-)

Thanks in advance greetz Peter


'Module om icoontjes aan een menu toe te voegen

Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Windows.Forms


Module IconsMenuMain

    Dim m_Font As New Font("Arial", 8)

    Sub MeasureItems(ByVal EvMeasureItem As
System.Windows.Forms.MeasureItemEventArgs, ByVal Mi _  As  MenuItem)
        Try
            Dim sf As StringFormat = New StringFormat()
            sf.HotkeyPrefix = HotkeyPrefix.Show
            sf.SetTabStops(60, New Single() {0})
            If Mi.Text <> "-" Then
                EvMeasureItem.ItemHeight = 22
            Else
                EvMeasureItem.ItemHeight = 7
            End If

            EvMeasureItem.ItemWidth =
CInt(EvMeasureItem.Graphics.MeasureString(GetRealText(Mi), _
                                                                 m_Font,
10000, sf).Width) + 30
            sf.Dispose()
            sf = Nothing
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
    Sub DrawItems(ByVal EvDrawItems As
System.Windows.Forms.DrawItemEventArgs, ByVal Mi As _
MenuItem, ByVal m_Icon As Icon)
        Try
            Dim blnNoMoreVisible As Boolean = False
            Dim br As Brush
            Dim br2 As Brush
            Dim fDisposeBrush As Boolean
            Dim rand As Pen

            Dim rcBk As Rectangle = EvDrawItems.Bounds
            rcBk.Height -= 2
            rcBk.Width -= 2
            If CBool(EvDrawItems.State And DrawItemState.Selected) Then
                br = New LinearGradientBrush(rcBk, Color.CadetBlue,
Color.LightBlue, 0)
                fDisposeBrush = True
                rand = New Pen(Color.DarkBlue, 1)
                EvDrawItems.Graphics.FillRectangle(br, rcBk)
                EvDrawItems.Graphics.DrawRectangle(rand, rcBk)

            Else
                br = SystemBrushes.Control
                br2 = New SolidBrush(Color.WhiteSmoke)
                rand = System.Drawing.SystemPens.Control
                EvDrawItems.Graphics.DrawRectangle(rand, rcBk)
                rcBk.X += 24
                rcBk.Width -= 23
                'rcBk.Y -= 1
                rcBk.Height += 2
                EvDrawItems.Graphics.FillRectangle(br2, rcBk)
                rcBk.X = 0
                rcBk.Width = 24
                EvDrawItems.Graphics.FillRectangle(br, rcBk)
                br2.Dispose()

            End If

            If fDisposeBrush Then br.Dispose()
            br = Nothing

            Dim sf As StringFormat = New StringFormat
            sf.HotkeyPrefix = HotkeyPrefix.Show
            sf.SetTabStops(60, New Single() {0})
            If Mi.Enabled Then
                br = New SolidBrush(EvDrawItems.ForeColor)
            Else
                br = New SolidBrush(Color.Gray)
            End If


            EvDrawItems.Graphics.DrawString(GetRealText(Mi), m_Font, br, _
                                            EvDrawItems.Bounds.Left + 25, _
                                            EvDrawItems.Bounds.Top + 2, sf)

            br.Dispose()
            br = Nothing
            sf.Dispose()
            sf = Nothing
            If Not m_Icon Is Nothing Then
                If Not Mi.Checked Then
                    EvDrawItems.Graphics.DrawIcon(m_Icon,
EvDrawItems.Bounds.Left + 2, _
                                                  EvDrawItems.Bounds.Top +
2)
                Else
                    EvDrawItems.Graphics.DrawIcon(m_Icon,
EvDrawItems.Bounds.Left + 2, _
                                                  EvDrawItems.Bounds.Top +
2)

                End If

            End If

            If Mi.Text = "-" Then
                EvDrawItems.Graphics.DrawLine(SystemPens.Control, 28,
EvDrawItems.Bounds.Top + 2, _ EvDrawItems.Bounds.Width,
EvDrawItems.Bounds.Top + 2)
            End If



            'Part for the border round all the menuitems
            If Mi.Index = 0 Then
                EvDrawItems.Graphics.DrawLine(Pens.Black, 1, 0,
EvDrawItems.Bounds.Width, 0)
                EvDrawItems.Graphics.DrawLine(Pens.Black, 1, 0, 1,
EvDrawItems.Bounds.Height)
                EvDrawItems.Graphics.DrawLine(Pens.Black,
EvDrawItems.Bounds.Width - 1, 0, _ EvDrawItems.Bounds.Width - 1,
EvDrawItems.Bounds.Height)
                If Mi.Index = Mi.Parent.MenuItems.Count - 1 Then
                    EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
EvDrawItems.Bounds.Top + _ EvDrawItems.Bounds.Height - 1,
EvDrawItems.Bounds.Width, EvDrawItems.Bounds.Top + _
EvDrawItems.Bounds.Height - 1)
                End If
            Else
                If Mi.Index < Mi.Parent.MenuItems.Count - 1 Then
                    EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
EvDrawItems.Bounds.Top, 1, _ EvDrawItems.Bounds.Top +
EvDrawItems.Bounds.Height)
                    EvDrawItems.Graphics.DrawLine(Pens.Black,
EvDrawItems.Bounds.Width - 1, EvDrawItems.Bounds.Top,
EvDrawItems.Bounds.Width - 1, EvDrawItems.Bounds.Top + _
EvDrawItems.Bounds.Height)
                    For i As Integer = Mi.Index + 1 To
Mi.Parent.MenuItems.Count - 1
                        If Mi.Parent.MenuItems(i).Visible = False Then
                            blnNoMoreVisible = True
                        Else
                            blnNoMoreVisible = False
                        End If
                    Next
                    If blnNoMoreVisible = True Then
                        EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
EvDrawItems.Bounds.Top + _  EvDrawItems.Bounds.Height - 1,
EvDrawItems.Bounds.Width, EvDrawItems.Bounds.Top + _
EvDrawItems.Bounds.Height - 1)
                        blnNoMoreVisible = False
                    End If
                End If
                If Mi.Index = Mi.Parent.MenuItems.Count - 1 Then
                    EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
EvDrawItems.Bounds.Top + _ EvDrawItems.Bounds.Height - 1,
EvDrawItems.Bounds.Width, EvDrawItems.Bounds.Top + _
EvDrawItems.Bounds.Height - 1)
                    EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
EvDrawItems.Bounds.Top, 1, _ EvDrawItems.Bounds.Top +
EvDrawItems.Bounds.Height)
                    EvDrawItems.Graphics.DrawLine(Pens.Black,
EvDrawItems.Bounds.Width - 1, _ EvDrawItems.Bounds.Top,
EvDrawItems.Bounds.Width - 1, EvDrawItems.Bounds.Top + _
EvDrawItems.Bounds.Height)
                End If
            End If
            'end of part for the border round the menuitems

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Function GetRealText(ByVal Mi As MenuItem) As String
        Try
            Dim s As String = Mi.Text
            If Mi.ShowShortcut And Mi.Shortcut <> Shortcut.None Then
                Dim k As Keys = CType(Mi.Shortcut, Keys)
                s = s & Convert.ToChar(9) & _

TypeDescriptor.GetConverter(GetType(Keys)).ConvertToString(k)
            End If
            Return s & StrDup(4, " ")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Function

End Module
Author
15 Apr 2005 8:07 AM
Peter
Thanks Ken I'll try it on monday because I haven't got access to my dot net
machine today and the hole weekend.

Greetz Peter

Show quoteHide quote
"Ken Tucker [MVP]" <vb***@bellsouth.net> schreef in bericht
news:#dXwIaWQFHA.3404@TK2MSFTNGP12.phx.gbl...
> Peter,
>
>     You are drawing the border then painting over it.  Try this instead.
>
>     Sub DrawItems(ByVal EvDrawItems As
> System.Windows.Forms.DrawItemEventArgs, ByVal Mi As _
>  MenuItem, ByVal m_Icon As Icon)
>         Try
>             Dim blnNoMoreVisible As Boolean = False
>             Dim br As Brush
>             Dim br2 As Brush
>             Dim fDisposeBrush As Boolean
>             Dim rand As Pen
>
>             Dim rcBk As Rectangle = EvDrawItems.Bounds
>             rcBk.Height -= 2
>             rcBk.Width -= 2
>             If CBool(EvDrawItems.State And DrawItemState.Selected) Then
>                 br = New LinearGradientBrush(rcBk, Color.CadetBlue,
> Color.LightBlue, 0)
>                 fDisposeBrush = True
>                 rand = New Pen(Color.DarkBlue, 1)
>                 EvDrawItems.Graphics.FillRectangle(br, rcBk)
>                 EvDrawItems.Graphics.DrawRectangle(rand, rcBk)
>
>             Else
>                 br = SystemBrushes.Control
>                 br2 = New SolidBrush(Color.WhiteSmoke)
>                 rand = System.Drawing.SystemPens.Control
>                 rcBk.X += 24
>                 rcBk.Width -= 23
>                 'rcBk.Y -= 1
>                 rcBk.Height += 2
>                 EvDrawItems.Graphics.FillRectangle(br2, rcBk)
>                 rcBk.X = 0
>                 rcBk.Width = 24
>                 EvDrawItems.Graphics.FillRectangle(br, rcBk)
>                 EvDrawItems.Graphics.DrawRectangle(rand, rcBk)
>                 br2.Dispose()
>
>             End If
> etc.
>
>
> Ken
> ----------------------
> "Peter Proost" <pproost@nospam.hotmail.com> wrote in message
> news:eTUkU1PQFHA.3416@TK2MSFTNGP10.phx.gbl...
> Hi, I've got the following ownerdraw menu:
>
> drag a mainmenu on a form and add some menuitems to it, set all the
> menuitems to ownerdraw = true
>
> and for every menuitem add this code (replace nothing with an ico if you
> want to show an icon in the menu)
> also add a module and copy paste the code at the bottom of the message.
>
> Private Sub MenuItem1_DrawItem1(ByVal sender As Object, ByVal e As _
> System.Windows.Forms.DrawItemEventArgs) Handles MenuItem1.DrawItem
>     DrawItems(e, MenuItem1, Nothing)
> End Sub
>
> Private Sub MenuItem1_MeasureItem1(ByVal sender As Object, ByVal e As _
> System.Windows.Forms.MeasureItemEventArgs) Handles MenuItem1.MeasureItem
>     MeasureItems(e, MenuItem1)
> End Sub
>
> I've got it working ok, even a ____________ in a menu can be ownerdrawn,
but
> this afternoon I was playing with my code and I decided I wanted to add a
> black border to the menuitems like VS2003 IDE menu's.
> As you will see I was able to add the black borders, there's even a check
to
> see if the currently drawn menuitem is the last visible one and handles
it.
> But I can't draw the border on the actual menuitems' border, if anyone
could
> help me with this I would appreciate it very much, if not I'll just remove
> the border part because I think it looks good even without the black
borders
> :-)
>
> Thanks in advance greetz Peter
>
>
> 'Module om icoontjes aan een menu toe te voegen
>
> Imports System
> Imports System.ComponentModel
> Imports System.Drawing
> Imports System.Drawing.Drawing2D
> Imports System.Drawing.Text
> Imports System.Windows.Forms
>
>
> Module IconsMenuMain
>
>     Dim m_Font As New Font("Arial", 8)
>
>     Sub MeasureItems(ByVal EvMeasureItem As
> System.Windows.Forms.MeasureItemEventArgs, ByVal Mi _  As  MenuItem)
>         Try
>             Dim sf As StringFormat = New StringFormat()
>             sf.HotkeyPrefix = HotkeyPrefix.Show
>             sf.SetTabStops(60, New Single() {0})
>             If Mi.Text <> "-" Then
>                 EvMeasureItem.ItemHeight = 22
>             Else
>                 EvMeasureItem.ItemHeight = 7
>             End If
>
>             EvMeasureItem.ItemWidth =
> CInt(EvMeasureItem.Graphics.MeasureString(GetRealText(Mi), _
>                                                                  m_Font,
> 10000, sf).Width) + 30
>             sf.Dispose()
>             sf = Nothing
>         Catch ex As Exception
>             MsgBox(ex.ToString)
>         End Try
>     End Sub
>     Sub DrawItems(ByVal EvDrawItems As
> System.Windows.Forms.DrawItemEventArgs, ByVal Mi As _
>  MenuItem, ByVal m_Icon As Icon)
>         Try
>             Dim blnNoMoreVisible As Boolean = False
>             Dim br As Brush
>             Dim br2 As Brush
>             Dim fDisposeBrush As Boolean
>             Dim rand As Pen
>
>             Dim rcBk As Rectangle = EvDrawItems.Bounds
>             rcBk.Height -= 2
>             rcBk.Width -= 2
>             If CBool(EvDrawItems.State And DrawItemState.Selected) Then
>                 br = New LinearGradientBrush(rcBk, Color.CadetBlue,
> Color.LightBlue, 0)
>                 fDisposeBrush = True
>                 rand = New Pen(Color.DarkBlue, 1)
>                 EvDrawItems.Graphics.FillRectangle(br, rcBk)
>                 EvDrawItems.Graphics.DrawRectangle(rand, rcBk)
>
>             Else
>                 br = SystemBrushes.Control
>                 br2 = New SolidBrush(Color.WhiteSmoke)
>                 rand = System.Drawing.SystemPens.Control
>                 EvDrawItems.Graphics.DrawRectangle(rand, rcBk)
>                 rcBk.X += 24
>                 rcBk.Width -= 23
>                 'rcBk.Y -= 1
>                 rcBk.Height += 2
>                 EvDrawItems.Graphics.FillRectangle(br2, rcBk)
>                 rcBk.X = 0
>                 rcBk.Width = 24
>                 EvDrawItems.Graphics.FillRectangle(br, rcBk)
>                 br2.Dispose()
>
>             End If
>
>             If fDisposeBrush Then br.Dispose()
>             br = Nothing
>
>             Dim sf As StringFormat = New StringFormat
>             sf.HotkeyPrefix = HotkeyPrefix.Show
>             sf.SetTabStops(60, New Single() {0})
>             If Mi.Enabled Then
>                 br = New SolidBrush(EvDrawItems.ForeColor)
>             Else
>                 br = New SolidBrush(Color.Gray)
>             End If
>
>
>             EvDrawItems.Graphics.DrawString(GetRealText(Mi), m_Font, br, _
>                                             EvDrawItems.Bounds.Left + 25,
_
>                                             EvDrawItems.Bounds.Top + 2,
sf)
>
>             br.Dispose()
>             br = Nothing
>             sf.Dispose()
>             sf = Nothing
>             If Not m_Icon Is Nothing Then
>                 If Not Mi.Checked Then
>                     EvDrawItems.Graphics.DrawIcon(m_Icon,
> EvDrawItems.Bounds.Left + 2, _
>                                                   EvDrawItems.Bounds.Top +
> 2)
>                 Else
>                     EvDrawItems.Graphics.DrawIcon(m_Icon,
> EvDrawItems.Bounds.Left + 2, _
>                                                   EvDrawItems.Bounds.Top +
> 2)
>
>                 End If
>
>             End If
>
>             If Mi.Text = "-" Then
>                 EvDrawItems.Graphics.DrawLine(SystemPens.Control, 28,
> EvDrawItems.Bounds.Top + 2, _ EvDrawItems.Bounds.Width,
> EvDrawItems.Bounds.Top + 2)
>             End If
>
>
>
>             'Part for the border round all the menuitems
>             If Mi.Index = 0 Then
>                 EvDrawItems.Graphics.DrawLine(Pens.Black, 1, 0,
> EvDrawItems.Bounds.Width, 0)
>                 EvDrawItems.Graphics.DrawLine(Pens.Black, 1, 0, 1,
> EvDrawItems.Bounds.Height)
>                 EvDrawItems.Graphics.DrawLine(Pens.Black,
> EvDrawItems.Bounds.Width - 1, 0, _ EvDrawItems.Bounds.Width - 1,
> EvDrawItems.Bounds.Height)
>                 If Mi.Index = Mi.Parent.MenuItems.Count - 1 Then
>                     EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
> EvDrawItems.Bounds.Top + _ EvDrawItems.Bounds.Height - 1,
> EvDrawItems.Bounds.Width, EvDrawItems.Bounds.Top + _
> EvDrawItems.Bounds.Height - 1)
>                 End If
>             Else
>                 If Mi.Index < Mi.Parent.MenuItems.Count - 1 Then
>                     EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
> EvDrawItems.Bounds.Top, 1, _ EvDrawItems.Bounds.Top +
> EvDrawItems.Bounds.Height)
>                     EvDrawItems.Graphics.DrawLine(Pens.Black,
> EvDrawItems.Bounds.Width - 1, EvDrawItems.Bounds.Top,
> EvDrawItems.Bounds.Width - 1, EvDrawItems.Bounds.Top + _
> EvDrawItems.Bounds.Height)
>                     For i As Integer = Mi.Index + 1 To
> Mi.Parent.MenuItems.Count - 1
>                         If Mi.Parent.MenuItems(i).Visible = False Then
>                             blnNoMoreVisible = True
>                         Else
>                             blnNoMoreVisible = False
>                         End If
>                     Next
>                     If blnNoMoreVisible = True Then
>                         EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
> EvDrawItems.Bounds.Top + _  EvDrawItems.Bounds.Height - 1,
> EvDrawItems.Bounds.Width, EvDrawItems.Bounds.Top + _
> EvDrawItems.Bounds.Height - 1)
>                         blnNoMoreVisible = False
>                     End If
>                 End If
>                 If Mi.Index = Mi.Parent.MenuItems.Count - 1 Then
>                     EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
> EvDrawItems.Bounds.Top + _ EvDrawItems.Bounds.Height - 1,
> EvDrawItems.Bounds.Width, EvDrawItems.Bounds.Top + _
> EvDrawItems.Bounds.Height - 1)
>                     EvDrawItems.Graphics.DrawLine(Pens.Black, 1,
> EvDrawItems.Bounds.Top, 1, _ EvDrawItems.Bounds.Top +
> EvDrawItems.Bounds.Height)
>                     EvDrawItems.Graphics.DrawLine(Pens.Black,
> EvDrawItems.Bounds.Width - 1, _ EvDrawItems.Bounds.Top,
> EvDrawItems.Bounds.Width - 1, EvDrawItems.Bounds.Top + _
> EvDrawItems.Bounds.Height)
>                 End If
>             End If
>             'end of part for the border round the menuitems
>
>         Catch ex As Exception
>             MsgBox(ex.ToString)
>         End Try
>     End Sub
>
>     Function GetRealText(ByVal Mi As MenuItem) As String
>         Try
>             Dim s As String = Mi.Text
>             If Mi.ShowShortcut And Mi.Shortcut <> Shortcut.None Then
>                 Dim k As Keys = CType(Mi.Shortcut, Keys)
>                 s = s & Convert.ToChar(9) & _
>
> TypeDescriptor.GetConverter(GetType(Keys)).ConvertToString(k)
>             End If
>             Return s & StrDup(4, " ")
>         Catch ex As Exception
>             MsgBox(ex.ToString)
>         End Try
>     End Function
>
> End Module
>
>
>