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:
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:
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
:
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