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

Tagged as

ScrollBar Control with Different Visual Style using VB.NET 2008

, 9 Mar 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Why another Scroll Bar? The standard ScrollBar 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 Scroll Bar? The standard ScrollBar 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 ScrollBar.

Background

MBScrollBar is a ContextMenuStrip which inherits all the properties of simple Scroll Bar control. I added Microsoft Office 2007 like Visuals in MBScrollBar, also it supports mouse wheel. 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. MBScrollBar is the Scroll Bar which already contains MBScrollBarRenderer Class You Just add the reference of MBScrollBar.Dll and used it by Dragging and Dropping.

MBScrollBar Control

Code

The concept for this Scroll Bar came from the Microsoft Office 2007 Scroll Bar. I organized methods of MBScrollBar into layers like this:

Following methods which are responsible for rendering simple Scroll Bar like Microsoft office

This method Render Background of MBScrollBar item:

''' <summary>
    ''' Draw Background for MBScrollBar
    ''' </summary>
    ''' <param name="g">graphics As Graphics</param>
    ''' <param name="rect">Rect As Rectangle</param>
    ''' <param name="orientation">Orientation As MBScrollBarOrientation</param>
    Public Shared Sub DrawBackground(ByVal g As Graphics, ByVal rect As Rectangle, ByVal orientation As MBScrollBarOrientation)
        If (g Is Nothing) Then
            Throw New ArgumentNullException("g")
        End If
        If (rect.IsEmpty Or g.IsVisibleClipEmpty Or Not g.VisibleClipBounds.IntersectsWith(rect)) Then
            Return
        End If
        If (orientation = MBScrollBarOrientation.Vertical) Then
            DrawBackgroundVertical(g, rect)
        Else
            DrawBackgroundHorizontal(g, rect)
        End If   
 End Sub

This method Render Arrow Button of MBScrollBar Item:

''' <summary>
''' Draw Arrow Button For MBScrollBar
''' </summary>
''' <param name="g">graphics As Graphics</param>
''' <param name="rect">Rect As Rectangle</param>
''' <param name="state">State As MBScrollBarState</param>
''' <param name="arrowUp">ArrowUp As Boolean</param>
''' <param name="orientation">Orientation As MBScrollBarOrientation</param>
Public Shared Sub DrawArrowButton(ByVal g As Graphics, ByVal rect As Rectangle, 
    ByVal state As MBScrollBarArrowButtonState, ByVal arrowUp As Boolean, 
    ByVal orientation As MBScrollBarOrientation)
        If g Is Nothing Then
            Throw New ArgumentNullException("g")
        End If
        If rect.IsEmpty Or g.IsVisibleClipEmpty Or (
            Not g.VisibleClipBounds.IntersectsWith(rect)) Then
            Return
        End If
        If orientation = MBScrollBarOrientation.Vertical Then
            DrawArrowButtonVertical(g, rect, state, arrowUp)
        Else
            DrawArrowButtonHorizontal(g, rect, state, arrowUp)
        End If
    End Sub

This method Handles painting of MBScrollBar:

''' <summary>
''' Handles MBScrollBar Mouse Wheel
''' </summary>
Protected Overrides Sub OnMouseWheel(ByVal e As System.Windows.Forms.MouseEventArgs)
        MyBase.OnMouseWheel(e)
        If (Me._Value < Me.Minimum Or Me._Value > Me.Maximum) Then
            Return
        Else
            If e.Delta > 0 Then
                Me._Value = Me._Value - 1
            Else
                Me._Value = Me._Value + 1
            End If
            If Me._Value > 100 Then Me._Value = 100
            If Me._Value < 0 Then Me._Value = 0
        End If
        Me.ChangeThumbPosition(Me.GetThumbPosition())
        Me.Refresh()
    End Sub

Using the Code

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

History

  • MBScrollBar Version 1.0.

License

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

Share

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

 
Questioncreating custome controls PinmemberCool Smith25-May-12 11:57 

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 | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 9 Mar 2012
Article Copyright 2012 by Manoj K Bhoir
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid