Advanced TrackBar (Slider) Control with MAC Style (C#)
(continued)
(Full Size Image)
It's nicer when you put this control with other MAC Style controls, as shown below:

(Full Size Image)
Introduction
Think about developing an advanced TrackBar (Slider) control that supports MAC Style and many other features, at the same time working in the MAC-UI Suite project (a project focused on building a rich library of UI controls in .NET with MAC style—always a favorite of many people!).
Main Features
- Supports MAC style
- Vertical and horizontal trackbar
- Supports many Text Tick styles: None, TopLeft, BottomRight, or Both
- You can change Text Font and ForeColor for Text Tick
- Supports many Tick styles: None, TopLeft, BottomRight, or Both
- You can change TickColor, TickFrequency, and TickHeight
- You can change TrackerColor and TrackerSize
- You can change TrackLineColor and TrackLineHeight
- Easy to use and integrate in Visual Studio .NET
- 100% compatible with the standard control in VS.NET
- 100% managed code
To explore the features of this TrackBar control, just download and run the Demo program.
Control Properties
Control Methods
| Method |
Description |
| Decrement |
Calls the Decrement() method to decrease the value displayed by an integer you specify. |
| Increment |
Calls the Increment() method to increase the value displayed by an integer you specify. |
| OnScroll |
Raises the Scroll event. |
| OnValueChanged |
Raises the ValueChanged event. |
| ResetAppearance |
Resets 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, code an event handle, and then 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 following methods for more detail:
- DrawTickTextLine()
- DrawTickLine()
- OnMouseDownSlider()
- OnMouseUpSlider()
- OnMouseMoveSlider()
Conclusion
Based on this core code, you quite easily can build other UI Styles for the TrackBar (for example, XP Style...). You can draw a Tracker of any style by loading pictures....
You easily can support all tracker shapes as on MAC (by loading and drawing the tracker's pictures). However, to optimize the memory usage, I haven't currently added them. I hope others find this control useful. Please feel free to report errors, issues, or requests.
About the Author
Founder & Manager of X-Component.
http://www.x-component.com
MCP with below MS certifications.
- MFC
- VC++ Desktop
- VC++ Distributed
Downloads
MAC_Slider_demo.zip - MAC_Slider_demo.zip
MAC_Slider_src.zip - MAC_Slider_src.zip