Click here to Skip to main content
13,449,298 members (44,130 online)
Click here to Skip to main content
Add your own
alternative version


87 bookmarked
Posted 29 Jan 2007

Owner-drawn trackbar(slider)

, 30 Jan 2007
Rate this:
Please Sign up or sign in to vote.
Implementing a Windows Forms owner-drawn trackbar (slider) control in C#.

Sample Image - ColorSlider.gif


This article presents owner-drawn trackbar control. Component is written entirely from scratch. All painting events are done by code. It’s got cool, modern look. The best thing is, however, the capability of changing slider’s thumb shape. It is done simply by providing appropriate graphics path.

Background (optional)

I always wanted to have cool slider for my audio player application. The best I could find here was Guinness4Strength's article. Unfortunately, I didn’t find it pretty enough, so I decided to write my own trackbar. Hopefully you like it.



  • ThumbSize - Gets or sets the size of the thumb
  • ThumbCustomShape - Gets or sets the thumb custom shape. Use ThumbRect property to determine bounding rectangle.
  • ThumbRoundRectSize - Gets or sets the size of the thumb round rectangle edges.
  • BorderRoundRectSize - Gets or sets the size of the border round rect.


  • Orientation - Gets or sets the orientation of Slider.
  • Value - Gets or sets the value of Slider.
  • Minimum - Gets or sets the minimum value.
  • Maximum - Gets or sets the maximum value.
  • SmallChange - Gets or sets trackbar's small change. It affects how to behave when directional keys are pressed
  • LargeChange - Gets or sets trackbar's large change. It affects how to behave when PageUp/PageDown keys are pressed


  • DrawFocusRectangle - Gets or sets a value indicating whether to draw focus rectangle.
  • DrawSemitransparentThumb - Gets or sets a value indicating whether to draw semitransparent thumb.
  • MouseEffects - Gets or sets whether mouse entry and exit actions have impact on how control look.
  • MouseWheelBarPartitions - Gets or sets the mouse wheel bar partitions.


  • ThumbOuterColor - Gets or sets the thumb outer color.
  • ThumbInnerColor - Gets or sets the inner color of the thumb.
  • ThumbPenColor - Gets or sets the color of the thumb pen.
  • BarOuterColor - Gets or sets the outer color of the bar.
  • BarInnerColor - Gets or sets the inner color of the bar.
  • BarPenColor - Gets or sets the color of the bar pen.
  • ElapsedOuterColor - Gets or sets the outer color of the elapsed.
  • ElapsedInnerColor - Gets or sets the inner color of the elapsed.

Points of Interest

This control will provide design-time support. Next version should contain custom properties editors.


  • 30.01.2007 - first version.
  • License

    This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


    About the Author

    Michal Brylka
    Architect Nokia Siemens Networks
    Poland Poland
    Michał is C# and whole .NET enthusiast. He graduated from computer science MSc studies at Wroclaw University of Technology, Poland.

    He is interested in photography and diving. He is member of PADI, currently with divemaster certificate.

    His favorite movies are Matrix, Amélie(Le Fabuleux Destin d'Amélie Poulain), Stargate SG-1 TV Serie and comedies of Mel Brooks.

    Michał lives in Wroclaw, Poland. To contact Michał, email him at michal.brylka[mail-'"at'"-sign]

    You may also be interested in...

    Comments and Discussions

    Bugthumb drawings are messed up in vertical orientation Pin
    Coder V20-Apr-17 7:10
    memberCoder V20-Apr-17 7:10 
    GeneralExactly what I needed! Pin
    Member 1073315012-Oct-14 5:50
    memberMember 1073315012-Oct-14 5:50 
    SuggestionGreat control - some suggestions Pin
    dr_thomas1-May-13 4:01
    memberdr_thomas1-May-13 4:01 
    QuestionthumbCustomShape Pin
    Ultiblade11-Mar-13 3:54
    memberUltiblade11-Mar-13 3:54 
    QuestionVertical orientation - reversed Pin
    thewampek5-Feb-13 5:09
    memberthewampek5-Feb-13 5:09 
    SuggestionMessage Removed Pin
    27-Dec-12 20:37
    memberRavinduL27-Dec-12 20:37 
    Questionimage as pen? Pin
    Andres Santillan20-Sep-12 18:01
    memberAndres Santillan20-Sep-12 18:01 
    GeneralMy vote of 5 Pin
    Member 90334004-Jun-12 6:04
    memberMember 90334004-Jun-12 6:04 
    QuestionNice work thanks. My vote is 5 Pin
    IssaharNoam11-Jan-12 22:18
    memberIssaharNoam11-Jan-12 22:18 
    QuestionPanel scrolls on mouse wheel before trackbar Pin
    howardfarrar27-Sep-10 6:21
    memberhowardfarrar27-Sep-10 6:21 
    AnswerRe: Panel scrolls on mouse wheel before trackbar Pin
    howardfarrar28-Sep-10 1:13
    memberhowardfarrar28-Sep-10 1:13 
    GeneralMy vote of 5 Pin
    Xmen W.K.16-Jul-10 15:48
    memberXmen W.K.16-Jul-10 15:48 
    Generalgood control Pin
    securigy19-Jun-10 0:29
    membersecurigy19-Jun-10 0:29 
    GeneralVery cool, small addition I did for myself Pin
    IssaharNoam22-Mar-09 0:38
    memberIssaharNoam22-Mar-09 0:38 
    Thanks for this good implementation.
    I did small change in order to allow fully hide the border. In following case in mouse over event, I found that transparent border appeared because was lightened.

    Here is my fix for myself
    public static Color[] LightenColors(params Color[] colorsToLighten)
                Color[] colorsToReturn = new Color[colorsToLighten.Length];
                for (int i = 0; i < colorsToLighten.Length; i++)
                        colorsToReturn[i] = colorsToLighten[i];
                        colorsToReturn[i] = ControlPaint.Light(colorsToLighten[i]);
                return colorsToReturn;

    GeneralRe: Very cool, small addition I did for myself Pin
    Xmen W.K.16-Jul-10 15:50
    memberXmen W.K.16-Jul-10 15:50 
    Questionorientation slider value reversed Pin
    TVW036-Mar-09 12:11
    memberTVW036-Mar-09 12:11 
    AnswerRe: orientation slider value reversed [modified] Pin
    tgpfarm11027-Mar-09 14:30
    membertgpfarm11027-Mar-09 14:30 
    GeneralRe: orientation slider value reversed [modified] Pin
    Mark Cortejo24-Jul-14 14:55
    memberMark Cortejo24-Jul-14 14:55 
    AnswerRe: orientation slider value reversed Pin
    Michal Brylka8-Mar-09 8:57
    memberMichal Brylka8-Mar-09 8:57 
    GeneralBrilliant implementation! Following slight change I did for myself Pin
    IssaharNoam23-Feb-09 0:42
    memberIssaharNoam23-Feb-09 0:42 
    GeneralRe: Brilliant implementation! Following slight change I did for myself Pin
    Michal Brylka8-Mar-09 8:42
    memberMichal Brylka8-Mar-09 8:42 
    GeneralFantastic! Pin
    -Sean-20-Feb-09 11:38
    member-Sean-20-Feb-09 11:38 
    GeneralRe: Fantastic! Pin
    Michal Brylka8-Mar-09 6:36
    memberMichal Brylka8-Mar-09 6:36 
    QuestionConversion to VB? Pin
    shalan9918-Oct-07 22:59
    membershalan9918-Oct-07 22:59 
    GeneralRe: Conversion to VB? Pin
    Michal Brylka22-Feb-08 2:50
    memberMichal Brylka22-Feb-08 2:50 

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

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

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web01 | 2.8.180318.3 | Last Updated 30 Jan 2007
    Article Copyright 2007 by Michal Brylka
    Everything else Copyright © CodeProject, 1999-2018
    Layout: fixed | fluid