|
|
|
Click here to copy the following block |
Imports System.Drawing Imports System.Windows.Forms
Public Class ColorMenuItem : Inherits MenuItem
Public m_Color As Color
Sub New(ByVal color As Color) MyBase.New("")
Me.OwnerDraw = True m_Color = color End Sub
Sub New(ByVal color As Color, ByVal eventHandler As EventHandler) MyBase.New("", eventHandler)
Me.OwnerDraw = True m_Color = color End Sub
Public Property Color() As Color Get Return m_Color End Get Set(ByVal Value As Color) m_Color = Value End Set End Property
Protected Overrides Sub OnMeasureItem(ByVal e As MeasureItemEventArgs) MyBase.OnMeasureItem(e)
e.ItemHeight = SystemInformation.MenuHeight - 4 e.ItemWidth = 40 End Sub
Protected Overrides Sub OnDrawItem(ByVal e As DrawItemEventArgs) MyBase.OnDrawItem(e)
Dim brBack As Brush If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then brBack = SystemBrushes.Highlight Else brBack = SystemBrushes.Menu End If e.Graphics.FillRectangle(brBack, e.Bounds)
Dim brColorBox As Brush = New SolidBrush(m_Color) Dim rect As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, _ e.Bounds.Height) rect.Inflate(-5, -3) e.Graphics.FillRectangle(brColorBox, rect) e.Graphics.DrawRectangle(New Pen(Color.Black), New Rectangle(rect.X, _ rect.Y, rect.Width, rect.Height)) End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Me.Menu = New MainMenu() Dim mnuColors As MenuItem = New MenuItem("Colors") Me.Menu.MenuItems.Add(mnuColors) mnuColors.MenuItems.Add(New ColorMenuItem(Color.Green, _ New EventHandler(AddressOf mnuColor_Click))) mnuColors.MenuItems.Add(New ColorMenuItem(Color.Navy, _ New EventHandler(AddressOf mnuColor_Click))) mnuColors.MenuItems.Add(New ColorMenuItem(Color.Purple, _ New EventHandler(AddressOf mnuColor_Click))) mnuColors.MenuItems.Add(New ColorMenuItem(Color.Red, _ New EventHandler(AddressOf mnuColor_Click))) mnuColors.MenuItems.Add(New ColorMenuItem(Color.Lime, _ New EventHandler(AddressOf mnuColor_Click))) mnuColors.MenuItems.Add(New ColorMenuItem(Color.Yellow, _ New EventHandler(AddressOf mnuColor_Click))) mnuColors.MenuItems.Add(New MenuItem("Other color...", _ New EventHandler(AddressOf mnuColor_Click))) End Sub
Private Sub mnuColor_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Dim bgColor As Color
If TypeOf sender Is ColorMenuItem Then bgColor = CType(sender, ColorMenuItem).Color Else End If
Me.BackColor = bgColor End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|