Click here to Skip to main content
14,024,527 members
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 16 Jul 2006
Licenced CPOL

Custom Menus Made Easy

, 16 Jul 2006
Rate this:
Please Sign up or sign in to vote.
An easy way to make your menus stand out.

Sample Image - ColorObject.jpg


Microsoft has upgraded the basic MenuStrip object. Now you can easily have images with it, woohoo! What they didn't do, is make you able to change colors (and by change colors, I mean gradient colors), and let's face it, if your GUI isn't blue, then why would you have a blue menu? The user might be a little confused. And, that's where this comes in; instead of paying for some over-priced control, you can use the ToolstripProfessionalRenderer, and the best part is that I have wrapped everything you need into a nice little control.

How it Works

This control was a bit interesting to make. I am sure people will point out code issues and stuff, but keep in mind, I wasn't originally going to put this on the web. Back to the code, it uses the ToolstripProfessionalRenderer with an inherited ProfessionalColorTable. What I then did was override almost all MenuStrip properties with my own. This is where it gets messy. Since the original properties are ReadOnly and we want to write them, I had to create another set of properties to write to the local variables the ReadOnly variables get their information from. Then, to make it accessible from an object, I had to put the writeable properties in a custom object, then create a way for the object and the class to share data.

How to Use

Overall, not so bad, eh? This control is pretty easy to use, and from what I can find, there is only one bug which I have yet to find an answer to. This is how to use the ColorObject:

First, you must declare the ColorObjectRenderer to be the renderer of the MenuStrip.

Public Sub New()

    ' This call is required by the Windows Form Designer.

    ' Add any initialization after the InitializeComponent() call.

    ToolStripManager.Renderer = Me.ColorObject1.Renderer

End Sub

This tells the MenuStrip to be rendered using Me.ColorObject1.Renderer. All the other things are taken care of. Renderer is a property of my object, just FYI. Now, here is how to use it and where the bug is. In any method, just change one of the color properties. Simple, right? But there is a problem, the control isn't automatically redrawn; after you change the color, you have to Invalidate the MenuStrip to redraw. I haven't found a way to programmatically do this, seeing as there isn't a way to access the menu item my object renders. If anyone knows a way around this, please tell me so I can update my code.

Private Sub AnySub()
    Dim clr As New ColorDialog

    With clr
        If .ShowDialog = Windows.Forms.DialogResult.OK And .Color <> Nothing Then
            Me.ColorObject1.SecondMenuBarColor = .Color
        End If
    End With
End Sub


I hope you found this article helpful. If you didn't, please leave a comment telling me why, so next time I can do better. Thanks!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
I am iwdu15, a college frosh who will be majoring in Computer Science. I use VB.Net, C#, C++, J#, Java, and some C.

You may also be interested in...

Comments and Discussions

GeneralFont Color Pin
JoeFisher7130-Sep-08 3:06
memberJoeFisher7130-Sep-08 3:06 
GeneralBlack Theme Pin
JoeFisher7126-Sep-08 11:00
memberJoeFisher7126-Sep-08 11:00 
GeneralRe: Black Theme Pin
sokket29-Sep-08 15:36
membersokket29-Sep-08 15:36 
GeneralThank U so much Pin
Nguyen Dinh Trung28-Jun-07 0:33
memberNguyen Dinh Trung28-Jun-07 0:33 
GeneralRe: Thank U so much Pin
iwdu15028-Jun-07 11:46
memberiwdu15028-Jun-07 11:46 
GeneralThanks! Pin
Lividum23-Feb-07 17:46
memberLividum23-Feb-07 17:46 
GeneralRe: Thanks! Pin
iwdu15024-Feb-07 15:43
memberiwdu15024-Feb-07 15:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190419.4 | Last Updated 16 Jul 2006
Article Copyright 2006 by iwdu150
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid