|
-
Mar 31st, 2005, 03:09 PM
#1
Thread Starter
New Member
Parent item in Mainmenu - ownerdraw?
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:
Private Sub _DrawMenuItem(ByVal sender As Object, ByRef e As System.Windows.Forms.DrawItemEventArgs, ByVal theIcon As String)
Dim MenuFont As Font
Dim FillColor As Color
Dim BorderColor As Color
Dim FontColor As Color
Dim myRectangle As New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.X + 24, e.Bounds.Height)
Dim myLinearGradientBrush As New LinearGradientBrush(myRectangle, Color.FromArgb(249, 249, 255), Color.FromArgb(165, 163, 189), LinearGradientMode.Horizontal)
MenuFont = New System.Drawing.Font("Verdana", 8)
With e.Graphics
If e.State = (DrawItemState.Selected Or DrawItemState.NoAccelerator) Or e.State = DrawItemState.Selected Then 'hovering
RaiseEvent ShowHandCursor()
FillColor = Color.FromArgb(195, 211, 233)
BorderColor = Color.FromArgb(133, 175, 232)
FontColor = Color.FromArgb(0, 70, 165)
.FillRectangle(New SolidBrush(FillColor), e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height - 1)
.DrawRectangle(New Pen(BorderColor), e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width - 2, e.Bounds.Height - 1)
.DrawString(sender.Text, MenuFont, New SolidBrush(FontColor), 30, e.Bounds.Y + 3)
Else 'not hovering
RaiseEvent ShowDefaultCursor()
FillColor = Color.White
FontColor = Color.Black
.FillRectangle(New SolidBrush(FillColor), e.Bounds.X + 24, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
.FillRectangle(myLinearGradientBrush, e.Bounds.X, e.Bounds.Y, e.Bounds.X + 24, e.Bounds.Height)
.DrawString(sender.Text, MenuFont, New SolidBrush(FontColor), 30, e.Bounds.Y + 3)
End If
If Not theIcon Is Nothing Then
.DrawIcon(New Icon(New Icon(theIcon), 16, 16), e.Bounds.X + 4, e.Bounds.Y + 1)
End If
End With
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|