Click here to Skip to main content
Click here to Skip to main content

MBToolStrip and StatusStrip

, 8 Mar 2012
Rate this:
Please Sign up or sign in to vote.
Why another Tool Strip or Status Strip? The standard ToolStrip/StatusStrip 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.

Introduction

Why another Tool Strip or Status Strip? The standard ToolStrip/StatusStrip 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 ToolStrip or StatusStrip Control.

Background

MBToolStrip/MBStatusStrip is a ToolStrip/StatusStrip which inherits all the properties of simple ToolStrip and StatusStrip control. I added Microsoft Office 2007 like Visuals in MBMenuStrip/MBToolStrip. The language used is VB.NET. There are so many classes which provides same functionality, but for that we have to write minimum two lines of code to add that renderer class in our application. MBToolStrip/MBStatusStrip is the MenuStrip which already contains MBMenuRenderer Class You Just add the reference of MBToolStrip.Dll and used it by Dragging and Dropping in your application.

Code

The concept for this Tool Strip came from the Microsoft Office 2007 Tool Strip and Status Strip. I organized methods of MBMenuRenderer into layers like this:

Following methods which are responsible for rendering simple Tool Strip and Status Strip like Microsoft office.

This method Render Background of MBToolStrip/MBStatusStrip item:

Private Sub RenderToolButtonBackground(ByVal g As Graphics, ByVal button As ToolStripButton, ByVal toolstrip As ToolStrip)
        If (button.Enabled) Then
            If (button.Checked) Then
                If (button.Pressed) Then
                    DrawGradientToolItem(g, button, _itemToolItemPressedColors)
                ElseIf (button.Selected) Then
                    DrawGradientToolItem(g, button, _itemToolItemCheckPressColors)
                Else
                    DrawGradientToolItem(g, button, _itemToolItemCheckedColors)
                End If
            Else
                If (button.Pressed) Then
                    DrawGradientToolItem(g, button, _itemToolItemPressedColors)
                ElseIf (button.Selected) Then
                    DrawGradientToolItem(g, button, _itemToolItemSelectedColors)
                End If
            End If
        Else
            If (button.Selected) Then
                Dim mousePos As Point = toolstrip.PointToClient(Control.MousePosition)
                If (Not button.Bounds.Contains(mousePos)) Then DrawGradientToolItem(g, button, _itemDisabledColors)
            End If
        End If
    End Sub

This method Render Image of MBToolStrip/MBStatusStrip Item:

Protected Overrides Sub OnRenderItemImage(ByVal e As System.Windows.Forms.ToolStripItemImageRenderEventArgs)
        If TypeOf (e.ToolStrip) Is ContextMenuStrip Or TypeOf (e.ToolStrip) Is ToolStripDropDownMenu Then
            If Not (e.Image Is Nothing) Then
                If (e.Item.Enabled) Then
                    e.Graphics.DrawImage(e.Image, e.ImageRectangle)
                Else
                    ControlPaint.DrawImageDisabled(e.Graphics, e.Image, _
                                                   e.ImageRectangle.X, _
                                                   e.ImageRectangle.Y, _
                                                   Color.Transparent)
                End If
            End If
        Else
            MyBase.OnRenderItemImage(e)
        End If
    End Sub

This method Handles Text of MBToolStrip/MBStatusStrip:

Protected Overrides Sub OnRenderItemText(ByVal e As System.Windows.Forms.ToolStripItemTextRenderEventArgs)
        If TypeOf (e.ToolStrip) Is MenuStrip Or TypeOf (e.ToolStrip) Is ToolStrip Or _
                 TypeOf (e.ToolStrip) Is ContextMenuStrip Or _
                 TypeOf (e.ToolStrip) Is ToolStripDropDownMenu Then
            If (Not e.Item.Enabled) Then
                e.TextColor = _textDisabled
            Else
                If (TypeOf (e.ToolStrip) Is MenuStrip And Not e.Item.Pressed And Not e.Item.Selected) Then
                    e.TextColor = _textMenuStripItem
                ElseIf (TypeOf (e.ToolStrip) Is StatusStrip And Not e.Item.Pressed And Not e.Item.Selected) Then
                    e.TextColor = _textStatusStripItem
                Else
                    e.TextColor = _textContextMenuItem
                End If
                Using clearTypeGridFit As UseClearTypeGridFit = New UseClearTypeGridFit(e.Graphics)
                    MyBase.OnRenderItemText(e)
                End Using
            End If
        Else
            MyBase.OnRenderItemText(e)
        End If
    End Sub

Using the Code

It is very easy to use the MBToolStrip/MBStatusStrip in your application. Just add the reference of the provided DLL to your application and just drag and drop.

History

  • MBToolStrip and MBStatusStrip Version 1.0.

License

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..!!
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralMy vote of 5 PinmemberAlhoot20043-Feb-13 13:38 
GeneralRe: My vote of 5 PinmemberManoj K Bhoir5-Feb-13 0:45 
QuestionHow to change String flags on text rendering Pinmemberhackerspk10-Nov-12 7:57 
QuestionIs this translated from c#? PinmemberDaniel Nutu22-May-12 4:34 
Office 2007 ToolStrip Renderer[^]
AnswerRe: Is this translated from c#? PinmemberManoj K Bhoir24-May-12 21:45 
QuestionNice job Pinmembervbfengshui8-Mar-12 12:33 
AnswerRe: Nice job PinmemberManoj K Bhoir27-Mar-12 1:41 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 8 Mar 2012
Article Copyright 2012 by Manoj K Bhoir
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid