Click here to Skip to main content
13,558,664 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


13 bookmarked
Posted 14 Dec 2011
Licenced CPOL

MenuStrip Control with MSOffice Visual Styles using VB.NET

, 14 Dec 2011
Rate this:
Please Sign up or sign in to vote.
A User Control with Microsoft Office 2007 Visual Style


Why another MenuStrip? The standard MenuStrip is too limited in functionality and I couldn't find a custom control written that did all that I wanted. This is a User Control with Microsoft Office 2007 Visual Style. It is simple to use, just drop it on the form, and use it like the normal MenuStrip.


MBMenuStrip is a MenuStrip which inherits all the properties of simple MenuStrip control. I added Microsoft Office 2007 like Visuals in MBMenuStrip. The language used is VB.NET. There are so many classes which provide the same functionality, but for that we have to write minimum two lines of code to add that renderer class in our application. MBMenuStrip is the MenuStrip which already contains MBRenderer class. You Just add the reference of MBMenuStrip.dll and used it by dragging and dropping.


The concept for this MenuStrip came from the Microsoft Office 2007 Right Click Menu. I organized methods of MBMenuStrip into layers like this.

The following methods are responsible for rendering a simple MenuStrip like Microsoft Office.

This method Render Background of MBMenuStrip item:

Protected Overrides Sub OnRenderMenuItemBackground_
	(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
        If e.Item.Selected Then
            Dim g As Graphics = e.Graphics
            g.SmoothingMode = SmoothingMode.HighQuality
            Dim pa As GraphicsPath = New GraphicsPath()
            Dim rect As Rectangle = New Rectangle(2, 1, e.Item.Size.Width - 2, _
			e.Item.Size.Height - 1)
            DrawArc(rect, pa)
            Dim lgbrush As LinearGradientBrush = New LinearGradientBrush_
            	(rect, Color.White, Color.White, LinearGradientMode.Vertical)
            Dim pos As Single() = New Single(3) {0.0F, 0.4F, 0.45F, 1.0F}
            Dim colors As Color() = New Color(3) {GetColor(0, 50, 100), _
            	GetColor(0, 0, 30), Color.FromArgb(R0, G0, B0), GetColor(0, 50, 100)}
            Dim mix As ColorBlend = New ColorBlend()
            mix.Colors = colors
            mix.Positions = pos
            lgbrush.InterpolationColors = mix
            g.FillPath(lgbrush, pa)
            g.DrawPath(New Pen(StrokeColor), pa)
        End If
    End Sub

This method renders Image of MBMenuStrip Item:

Protected Overrides Sub OnRenderItemImage_
	(ByVal e As System.Windows.Forms.ToolStripItemImageRenderEventArgs)
        e.Graphics.SmoothingMode = SmoothingMode.HighQuality
        If Not (e.Image Is Nothing) Then
            imageheight = e.Item.Height - offsety * 2
            imagewidth = ((Convert.ToDouble(imageheight) / _
				e.Image.Height) * e.Image.Width)
        End If
        e.Graphics.DrawImage(e.Image, New Rectangle_
		(offsetx, offsety, imagewidth, imageheight))
    End Sub

This method handles painting of MBMenuStrip:

Public Sub DrawArc(ByVal re As Rectangle, ByVal pa As GraphicsPath)
        Dim _radiusX0Y0 As Int32 = _radius, _radiusXFY0 As Int32 = _radius, _
        	_radiusX0YF As Int32 = _radius, _radiusXFYF As Int32 = _radius
        pa.AddArc(re.X, re.Y, _radiusX0Y0, _radiusX0Y0, 180, 90)
        pa.AddArc(re.Width - _radiusXFY0, re.Y, _radiusXFY0, _radiusXFY0, 270, 90)
        pa.AddArc(re.Width - _radiusXFYF, _
	re.Height - _radiusXFYF, _radiusXFYF, _radiusXFYF, 0, 90)
        pa.AddArc(re.X, re.Height - _radiusX0YF, _radiusX0YF, _radiusX0YF, 90, 90)
    End Sub

Using the Code

It is very easy to use the MBMenuStrip in your application. Simply add the reference of the provided DLL to your application and just drag and drop.



  • MBMenuStrip Version 1.0


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


About the Author

Manoj K Bhoir
Software Developer
India India
It always seems good to hear about me, but the thing I do is I code. I'm Interested in Designing Windows Based Application, Web Applications and building Mobile Applications. Currently restricting it to Android 4.0 applications, building Internet Based Applications using ASP.NET and contributing to bring the student community to a position which will help technology to reach the greatest heights ever. A very Big fan of Microsoft & Android..!!

You may also be interested in...


Comments and Discussions

GeneralMy vote of 3 Pin
maheshsanika19-Dec-11 20:24
membermaheshsanika19-Dec-11 20:24 
GeneralMy vote of 1 Pin
Selvin14-Dec-11 4:38
memberSelvin14-Dec-11 4:38 
GeneralRe: My vote of 1 Pin
Manoj K Bhoir14-Dec-11 18:40
memberManoj K Bhoir14-Dec-11 18:40 
I ompletely agree with you Code used for Both controls is almost same but Both the Controls MenuStrip and ContextMenuStrip are Different from each other and these controls are ready to use by just Drag and Drop.
For better understanding and easy to use i make these two articles insted of combining them into one. Smile | :)

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 | Terms of Use | Mobile
Web01 | 2.8.180515.1 | Last Updated 14 Dec 2011
Article Copyright 2011 by Manoj K Bhoir
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid