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

Advanced TrackBar (Slider) Control with MAC Style (C# & VB.NET)

, 24 Nov 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
An advanced TrackBar (Slider) control that supports MAC Style and many other features
Sample Image - TrackBar_Demo.jpg

It's nicer when we put this control with other MAC Style controls as below:

Sample image


We think about developing an advanced TrackBar (Slider) control that supports MAC Style and many other features in the time working in ‘MAC-UI Suite' project (a project focus on building a rich library of UI controls with MAC style for .NET).

Main Features

  • Supports MAC style
  • Vertical and Horizontal trackbar
  • Supports many Text Tick styles: None, TopLeft, BottomRight, Both
  • You can change Text Font, ForeColor for Text Tick
  • Supports many Tick styles: None, TopLeft, BottomRight, Both
  • You can change TickColor, TickFrequency, TickHeight
  • You can change TrackerColor and TrackerSize
  • You can change TrackLineColor and TrackLineHeight
  • Easy to Use and Integrate in Visual Studio .NET
  • 100% compatible to the standard control in VS.NET
  • 100% managed code

To explore features of this TrackBar control, just download and run the demo program.

Control Properties

Property Description
AutoSize Gets or sets a value indicating whether the height or width of the track bar is being automatically sized.
BorderColor Gets or sets the border color of the control.
BorderStyle Gets or sets the border type of the trackbar control.
IndentHeight Gets or sets the height of indent (or Padding-Y).
IndentWidth Gets or sets the width of indent (or Padding-Y).
LargeChange Gets or sets a value to be added to or subtracted from the Value property when the slider is moved a large distance.
Maximum Gets or sets the upper limit of the range this MACTrackBar is working with.
Minimum Gets or sets the lower limit of the range this MACTrackBar is working with.
Orientation Gets or sets a value indicating the horizontal or vertical orientation of the track bar.
Size Gets or sets the height and width of the control.
SmallChange Gets or sets a value to be added to or subtracted from the Value property when the slider is moved a small distance.
TextTickStyle Gets or sets the text tick style of the trackbar. There are 4 styles for selection: None, TopLeft, BottomRight, Both.
TickColor Gets or sets the tick's Color of the control.
TickFrequency Gets or sets a value that specifies the delta between ticks drawn on the control.
TickHeight Gets or sets the height of tick.
TickStyle Gets or sets the tick style of the trackbar. There are 4 styles for selection: None, TopLeft, BottomRight, Both.
TrackerColor Gets or set tracker's color.
TrackerSize Gets or sets the tracker's size. The tracker's width must be greater or equal to tracker's height.
TrackLineColor Gets or sets the color of the track line.
TrackLineHeight Gets or sets the height of track line.
Value Gets or sets a numeric value that represents the current position of the slider on the track bar.

Control Methods

Methods Description
Decrement Call the Decrement() method to decrease the value displayed by an integer you specify
Increment Call the Increment() method to increase the value displayed by an integer you specify
OnScroll Raises the Scroll event.
OnValueChanged Raises the ValueChanged event.
ResetAppearance Reset the appearance properties after the UIStyle property.
SetRange Sets the minimum and maximum values for a TrackBar.

Control Events

Event Description
Scroll Occurs when either a mouse or keyboard action moves the slider.
ValueChanged Occurs when the property Value has been changed.

Using the Control

  • Download the source code and unzip it.
  • Open VS.NET's Tool menu and select "Add/Remove ToolBox Items".
  • Click "Browse", and navigate to the MACTrackBar.dll in the bin\Release directory of the source code.
  • Click Open and then OK, the MACTrackBar control will now be in your ToolBox. Just drag the control onto your form to use it.
  • Set the control's properties, and coding an event handle, and you press F5 to run your program.

Inside the Code

The calculation for all Orientation of the Tracker may be fairly complex and interesting.

Please read the below methods for more detail:

  • DrawTickTextLine()
  • DrawTickLine()
  • OnMouseDownSlider()
  • OnMouseUpSlider()
  • OnMouseMoveSlider()


Basing on this core code, you can build quite easily other UI Style for the TrackBar (e.g. XP Style...). You can draw the Tracker of any style by loading pictures...

We can support easily all tracker shapes as on MAC (by loading and drawing tracker's pictures). However, to optimize the memory usage, currently I didn't add them.

I hope others find this control useful. Please feel free to report errors, issues, or requests.


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


About the Author

Web Developer
Vietnam Vietnam
Founder & Manager of X-Component (MAC-UI Suite, XP-UI Suite, IDE-UI Suite...)
MCP with below MS certifications.
- VC++ Desktop
- VC++ Distributed

Comments and Discussions

QuestionChanging colors when control is disabled and enabled PinmemberMark Guzewski4-Oct-13 8:46 
QuestionThe name or namespace XComponent could not be found.. Pinmembertomb181-May-12 19:12 
GeneralMy vote of 5 PinmemberBill SerGio, Infomercial King4-May-11 21:28 
QuestionLicense Pinmembersavitabelgaonkar25-Apr-11 7:43 
Generalbugfix Pinmemberavramik23-Nov-10 5:34 
QuestionDecimal Steps Pinmembert v123-Nov-09 16:42 
GeneralMouse Position Bug Pinmemberrichardpb424-May-09 15:56 
QuestionError Pinmemberneonego4-Apr-09 19:46 
This occurs when the maximum value of slider has a large amount of value.
I used it in media player for example, setting it as a tracker for the position
of the media. Frown | :(
System.OverflowException was unhandled
Message="Arithmetic operation resulted in an overflow."
at XComponent.SliderBar.MACTrackBar.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at VRPlayer.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
GeneralHI PinmemberArun Raj.K18-Jul-08 8:28 
GeneralWhats to add a cool feature. Needs help! Pinmemberporati1-Jul-08 23:37 
Generalpls help me! i am having a dll file for custom control,how to upload it into my application Pinmembersaikalai19-Jun-08 1:03 
GeneralMulitple TrackPoints Pinmemberbizzysim6-Jul-07 10:41 
GeneralScroll event / Keyboard Pinmemberantoineplantier25-Jun-07 23:35 
QuestionRefresh Problem? PinmemberGalen_219-Jan-07 6:45 
GeneralTrackBar Pinmemberelavarasi14-Dec-06 21:46 
Generalothers styles PinmemberAplicativo27-Nov-06 23:53 
GeneralRe: others styles PinmemberNicolNghia30-Nov-06 23:21 
GeneralRe: others styles PinmemberAplicativo1-Dec-06 6:37 
GeneralGreat! PinmemberUnRusoDeCaracas24-Nov-06 10:28 
GeneralRe: Great! PinmemberNicolNghia25-Nov-06 2:20 
GeneralVery nice job! PinmemberGreg Cadmes15-Nov-06 11:41 
GeneralRe: Very nice job! [modified] PinmemberNicolNghia24-Nov-06 3:53 
QuestionMax value exeeded? Pinmemberdavelanton226-Sep-06 12:42 
AnswerRe: Max value exeeded? PinmemberNicolNghia25-Nov-06 2:17 
QuestionLicense PinmemberRobert Rohde23-Jul-06 21:47 

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
Web02 | 2.8.150129.1 | Last Updated 24 Nov 2006
Article Copyright 2006 by NicolNghia
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid