473,395 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1317
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.