472,811 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,811 software developers and data experts.

ownerdraw menu, help appreciated

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(GetRealT ext(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)).Convert ToString(k)
End If
Return s & StrDup(4, " ")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function

End Module
Nov 21 '05 #1
2 1291
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" <pp*****@nospam.hotmail.com> wrote in message
news:eT**************@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(GetRealT ext(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)).Convert ToString(k)
End If
Return s & StrDup(4, " ")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function

End Module

Nov 21 '05 #2
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

"Ken Tucker [MVP]" <vb***@bellsouth.net> schreef in bericht
news:#d**************@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" <pp*****@nospam.hotmail.com> wrote in message
news:eT**************@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(GetRealT ext(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)).Convert ToString(k)
End If
Return s & StrDup(4, " ")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function

End Module

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rob Mayo | last post by:
How can I force a MeasureItem message for an owner-dramn menu item? Here is the dilemma. I wrote a lovely little Component for owner-drawing all the menus on a form and making them look like...
0
by: Apollo440 | last post by:
If MenuItem.OwnerDraw Property is true,.NET framework does not recognize the overlapped accelerator keys. Is there a workaround? eg) +------+ |&Test | <- |&Tea | <- MenuItems has...
2
by: Stuart Norris | last post by:
Dear Group, I am new to c# and windows form designer - coming from a Motif background. I am attempting to develop an application for a touch screen and I need to have a menu system with a...
2
by: jm | last post by:
There are properties for OwnerDraw on ContextMenu items. I know it can be done with regular menus. I cannot find anyone doing it with the systray icon contextmenu (notifyicon.) Is it possible to...
0
by: Michel | last post by:
I come back with a new question regarding my OwnerDraw menu. That is a classical ownerDraw menu to add icon and some other color properties. My feature is to color all the menu bar with the...
0
by: Peter Proost | last post by:
Hi group, I was wondering if anyone has ever done this before, I've got a working ownerdrawn menu the only thing I can't get to work is to ownerdraw the items the get automaticaly created in a...
2
by: Peter Proost | last post by:
Hi group, I've got this ownerdraw menu module which I got from a site and modified to my personal needs, but the only problem I'm having is with the lines in a menu, when you type - as text, it...
0
by: genojoe | last post by:
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...
1
by: tmda | last post by:
I'm using OwnerDraw for some customization in my ListView - adding color to item backgrounds. I'm using the ListView specifically for it's OwnerDraw capability. I originally was using the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.