Click here to Skip to main content
11,412,833 members (74,386 online)
Click here to Skip to main content

Owner-drawn trackbar(slider)

, 30 Jan 2007 LGPL3
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

Introduction

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.

Properties

Appearance:

  • 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.

Values:

  • 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

Behavior:

  • 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.

Colors:

  • 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.

History

  • 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)

    Share

    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]op.pl.

    Comments and Discussions

     
    GeneralExactly what I needed! Pin
    Member 10733150 at 12-Oct-14 6:50
    memberMember 1073315012-Oct-14 6:50 
    SuggestionGreat control - some suggestions Pin
    dr_thomas at 1-May-13 5:01
    memberdr_thomas1-May-13 5:01 
    QuestionthumbCustomShape Pin
    Ultiblade at 11-Mar-13 4:54
    memberUltiblade11-Mar-13 4:54 
    QuestionVertical orientation - reversed Pin
    thewampek at 5-Feb-13 6:09
    memberthewampek5-Feb-13 6:09 
    SuggestionAdding ColorSlider to the VB ToolBox Pin
    RavinduL at 27-Dec-12 21:37
    memberRavinduL27-Dec-12 21:37 
    Questionimage as pen? Pin
    Andres Santillan at 20-Sep-12 19:01
    memberAndres Santillan20-Sep-12 19:01 
    GeneralMy vote of 5 Pin
    Member 9033400 at 4-Jun-12 7:04
    memberMember 90334004-Jun-12 7:04 
    QuestionNice work thanks. My vote is 5 Pin
    IssaharNoam at 11-Jan-12 23:18
    memberIssaharNoam11-Jan-12 23:18 
    QuestionPanel scrolls on mouse wheel before trackbar Pin
    howardfarrar at 27-Sep-10 7:21
    memberhowardfarrar27-Sep-10 7:21 
    AnswerRe: Panel scrolls on mouse wheel before trackbar Pin
    howardfarrar at 28-Sep-10 2:13
    memberhowardfarrar28-Sep-10 2:13 
    GeneralMy vote of 5 Pin
    Xmen W.K. at 16-Jul-10 16:48
    memberXmen W.K.16-Jul-10 16:48 
    Generalgood control Pin
    securigy at 19-Jun-10 1:29
    membersecurigy19-Jun-10 1:29 
    GeneralVery cool, small addition I did for myself Pin
    IssaharNoam at 22-Mar-09 1:38
    memberIssaharNoam22-Mar-09 1:38 
    GeneralRe: Very cool, small addition I did for myself Pin
    Xmen W.K. at 16-Jul-10 16:50
    memberXmen W.K.16-Jul-10 16:50 
    Questionorientation slider value reversed Pin
    TVW03 at 6-Mar-09 13:11
    memberTVW036-Mar-09 13:11 
    AnswerRe: orientation slider value reversed [modified] Pin
    tgpfarm1102 at 7-Mar-09 15:30
    membertgpfarm11027-Mar-09 15:30 
    GeneralRe: orientation slider value reversed [modified] Pin
    Mark Cortejo at 24-Jul-14 15:55
    memberMark Cortejo24-Jul-14 15:55 
    AnswerRe: orientation slider value reversed Pin
    Michal Brylka at 8-Mar-09 9:57
    memberMichal Brylka8-Mar-09 9:57 
    GeneralBrilliant implementation! Following slight change I did for myself Pin
    IssaharNoam at 23-Feb-09 1:42
    memberIssaharNoam23-Feb-09 1:42 
    GeneralRe: Brilliant implementation! Following slight change I did for myself Pin
    Michal Brylka at 8-Mar-09 9:42
    memberMichal Brylka8-Mar-09 9:42 
    GeneralFantastic! Pin
    -Sean- at 20-Feb-09 12:38
    member-Sean-20-Feb-09 12:38 
    GeneralRe: Fantastic! Pin
    Michal Brylka at 8-Mar-09 7:36
    memberMichal Brylka8-Mar-09 7:36 
    QuestionConversion to VB? Pin
    shalan99 at 18-Oct-07 23:59
    membershalan9918-Oct-07 23:59 
    GeneralRe: Conversion to VB? Pin
    Michal Brylka at 22-Feb-08 3:50
    memberMichal Brylka22-Feb-08 3:50 
    hi,

    you only need to extract control source to separate C# library and then add reference to it in your VB project

    Regards

    Michal Brylka

    Theory is when you know something, but it doesn't work.
    Practice is when something works, but you don't know why.
    Programmers combine theory and practice: Nothing works and they don't know why.

    GeneralSlight improvements Pin
    JeromeHordies at 16-Sep-07 6:07
    memberJeromeHordies16-Sep-07 6:07 
    GeneralRe: Slight improvements Pin
    Michal Brylka at 14-Feb-08 18:43
    memberMichal Brylka14-Feb-08 18:43 
    GeneralGreat control Pin
    Ross_MacGregor at 25-Jul-07 9:59
    memberRoss_MacGregor25-Jul-07 9:59 
    GeneralMulitple TrackPoints Pin
    bizzysim at 6-Jul-07 10:36
    memberbizzysim6-Jul-07 10:36 
    GeneralRe: Mulitple TrackPoints Pin
    Michal Brylka at 6-Jul-07 11:26
    memberMichal Brylka6-Jul-07 11:26 
    NewsGreat Control - added ToolStrip support Pin
    Thomas-H. at 28-Jun-07 6:08
    memberThomas-H.28-Jun-07 6:08 
    GeneralRe: Great Control - added ToolStrip support [modified] Pin
    Michal Brylka at 28-Jun-07 8:34
    memberMichal Brylka28-Jun-07 8:34 
    Generalyour control is very good,I want Two blocks in your control, Pin
    frequent at 30-May-07 19:55
    memberfrequent30-May-07 19:55 
    GeneralRe: your control is very good,I want Two blocks in your control, Pin
    Michal Brylka at 31-May-07 9:35
    memberMichal Brylka31-May-07 9:35 
    QuestionAccessiblity? Pin
    Zorbek at 5-Feb-07 22:59
    memberZorbek5-Feb-07 22:59 
    AnswerRe: Accessiblity? Pin
    Michal Brylka at 7-Feb-07 2:55
    memberMichal Brylka7-Feb-07 2:55 
    GeneralRe: Accessiblity? Pin
    Zorbek at 7-Feb-07 14:06
    memberZorbek7-Feb-07 14:06 
    GeneralInteresting idea Pin
    Pete O'Hanlon at 30-Jan-07 1:54
    memberPete O'Hanlon30-Jan-07 1:54 
    GeneralRe: Interesting idea Pin
    Michal Brylka at 30-Jan-07 16:52
    memberMichal Brylka30-Jan-07 16:52 
    GeneralAdd few thing to become ultimate ;) Pin
    The Monz at 30-Jan-07 1:42
    memberThe Monz30-Jan-07 1:42 
    GeneralRe: Add few thing to become ultimate ;) Pin
    Michal Brylka at 7-Feb-07 3:05
    memberMichal Brylka7-Feb-07 3:05 
    GeneralRe: Add few thing to become ultimate ;) Pin
    J.e.e.P at 21-Apr-09 3:31
    memberJ.e.e.P21-Apr-09 3:31 

    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
    Web03 | 2.8.150427.1 | Last Updated 30 Jan 2007
    Article Copyright 2007 by Michal Brylka
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid