Click here to Skip to main content
13,292,205 members (57,005 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


48 bookmarked
Posted 8 Dec 2011

Glass Style Button With Dropdown MenuList using VB.NET 2008

, 29 Dec 2011
Rate this:
Please Sign up or sign in to vote.
A user control with lots of properties and versatility


Why another Button? The standard Button 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 lots of properties and versatility. It is simple to use, just drop it on the form, adjust the design time properties, and use it like the normal Button.


MBGlassButton is a Button which inherits all the properties of a simple Button control. I added some extra functionalities in MBGlassButton like Glow, Split, Highlight, etc. The language used is VB.NET.

Control Properties

Here is the list of properties available in MBGlassButton:

  • Arrow: This property is used to set the arrow on MBGlassButton.
  • BaseColor: This property is used to set the Base Color of MBGlassButton.
  • BaseStrokeColor: This property is used to set the Base Stroke color of MBGlassButton.
  • OnColor: This property is used to set the on color of MBGlassButton.
  • OnStrokeColor: This property is used to set the On Stroke color of MBGlassButton.
  • PressColor: This property is used to set the Press Color of MBGlassButton.
  • PressStrokeColor: This property is used to set the Press Stroke Color of MBGlassButton.
  • ShowBase: This property is used to Show the Glow on MBGlassButton.
  • Radius: This property is used to set the corner Radius of MBGlassButton.
  • SplitButton: This property is used to Split MBGlassButton into two parts.
  • SplitDistance: This property is used to set the Split Distance of MBGlassButton.
  • SplitLocation: This property is used to Split MBGlassButton at a specific location.



The concept for this Button came from the Vista ‘Button’ or Windows 7 “Button”. I organized my paint event into layers like this:

Protected Overrides Sub OnPaint(ByVal pevent As System.Windows.Forms.PaintEventArgs)
        Dim g As Graphics = pevent.Graphics
        g.SmoothingMode = SmoothingMode.HighQuality
        g.InterpolationMode = InterpolationMode.High
        Dim r As Rectangle = New Rectangle(New Point(-1, -1), _
	New Size(Me.Width + _radius, Me.Height + _radius))
        Dim path As GraphicsPath = New GraphicsPath
        Dim rp As Rectangle = New Rectangle(New Point(0, 0), _
	New Size(Me.Width - 1, Me.Height - 1))
        DrawArc(rp, path)
        FillGradients(g, path)
End Sub

Following are some methods which provide a transparent look to MBGlassButton. This method draws the background for MBGlassButton.

Protected Overrides Sub OnCreateControl()
        A0 = BaseColor.A
        R0 = BaseColor.R
        G0 = BaseColor.G
        B0 = BaseColor.B
        _colorStroke = _baseStroke
        Dim r As Rectangle = New Rectangle(New Point(-1, -1), _
		New Size(Me.Width + _radius, Me.Height + _radius))
        If Me.Size <> Nothing Then
            Dim pathregion As GraphicsPath = New GraphicsPath
            DrawArc(r, pathregion)
            Me.Region = New Region(pathregion)
        End If
End Sub

This method draws the background shadow for MBGlassButton:

Public Sub DrawShadow(ByVal re As Rectangle, ByVal pa As GraphicsPath)
        Dim _radiusX0Y0 As Integer = _radius, _radiusXFY0 _
	As Integer = _radius, _radiusX0YF _
        	As Integer = _radius, _radiusXFYF As Integer = _radius
        Select Case _grouppos
            Case MB_GroupPos.Left
                _radiusXFY0 = 1
                _radiusXFYF = 1
            Case MB_GroupPos.Center
                _radiusX0Y0 = 1
                _radiusX0YF = 1
                _radiusXFY0 = 1
                _radiusXFYF = 1
            Case MB_GroupPos.Right
                _radiusX0Y0 = 1
                _radiusX0YF = 1
            Case MB_GroupPos.Top
                _radiusX0YF = 1
                _radiusXFYF = 1
            Case MB_GroupPos.Bottom
                _radiusX0Y0 = 1
                _radiusXFY0 = 1
        End Select
        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

This method handles the Menu List Rendering for MBGlassButton:

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) {GetRendererColor(0, 50, 100), _
            GetRendererColor(0, 0, 30), Color.FromArgb(R0, G0, B0), _
		GetRendererColor(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

Using the Code


Just add new context Menu Strip in your application and set it to MBGlassButton Context Menu Strip Property.


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


  • 12/8/2011: MBGlassButton Version 1.0
  • 12/26/2011: Updated demo and source code


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

QuestionButtons on left side of demo don't display the assigned ContextMenu Pin
jeffb4211-Dec-11 8:33
memberjeffb4211-Dec-11 8:33 
AnswerRe: Buttons on left side of demo don't display the assigned ContextMenu Pin
Manoj K Bhoir11-Dec-11 18:22
memberManoj K Bhoir11-Dec-11 18:22 
QuestionException when application is closed Pin
jeffb4211-Dec-11 8:28
memberjeffb4211-Dec-11 8:28 
AnswerRe: Exception when application is closed Pin
Manoj K Bhoir11-Dec-11 18:17
memberManoj K Bhoir11-Dec-11 18:17 
Thanks Jeff for your feedback and suggetions.I will implement this in MBGlassButton as soon as possible.

Thanks again. Smile | :)
QuestionLook like Office 2007 Pin
Đỗ Hồng Ngọc8-Dec-11 15:52
memberĐỗ Hồng Ngọc8-Dec-11 15:52 
AnswerRe: Look like Office 2007 Pin
Manoj K Bhoir8-Dec-11 19:52
memberManoj K Bhoir8-Dec-11 19:52 
Question.. Pin
freakyit8-Dec-11 11:09
memberfreakyit8-Dec-11 11:09 
AnswerRe: .. Pin
Manoj K Bhoir8-Dec-11 19:49
memberManoj K Bhoir8-Dec-11 19:49 
AnswerRe: .. Pin
Manoj K Bhoir8-Dec-11 20:07
memberManoj K Bhoir8-Dec-11 20:07 
Questionyeah Pin
freakyit8-Dec-11 11:05
memberfreakyit8-Dec-11 11:05 

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.171207.1 | Last Updated 29 Dec 2011
Article Copyright 2011 by Manoj K Bhoir
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid