Click here to Skip to main content
11,490,973 members (71,811 online)
Click here to Skip to main content

Round Slider Control

, 16 Mar 2000 108.4K 4.3K 61
Rate this:
Please Sign up or sign in to vote.
A round slider control to allow users to adjust an angle or similar values
  • Download demo project - 82 Kb
  • Download source files - 7 Kb
  • Sample Image - RoundSliderCtrl.jpg

    I needed a round slider control to let my users enter an angle. I thought this could be useful to others, so I wrote a general class for it using some of the functions from Chris Maunder's CRoundButton class.

    To use, simply add a slider to your dialog. Enlarge it until it covers an approximately square area.

    In your dialog class, associate a control variable (say m_rscMySlider), with the slider. If you have told class wizard about CRoundSliderCtrl, you will be able to select it when you define the control variable. If not, just go for CSliderCtrl and manually edit the definition in your dialog header file, changing CSliderCtrl to CRoundSliderCtrl. If you do not like using DDX then you can just subclass the control.

    In OnInitDialog() you would call SetRange(), SetPos(), etc. to customize the look and feel of the round slider control. The full API of the control is as follows:

    	// You may use '%ld' to show the slider value. Default: "%ld°"
    	virtual void SetText(const CString& strNewText);
    	virtual CString GetText() const;
    
    	// Default: 7, Minimum: 5
    	virtual void SetKnobRadius(const int nNewKnobRadius);
    	virtual int GetKnobRadius() const;
    
    	virtual void SetDragByKnobOnly(const bool bDragByKnobOnly);
    	virtual bool GetDragByKnobOnly() const;
    
    	// 0-359, 0 = Top, 90 = Right, 180 = Bottom, 270 = Left
    	virtual void SetZero(const int nZero);
    	virtual int GetZero() const;
    
    	// CW/CCW
    	virtual void SetInverted(const bool bNewInverted = true);
    	virtual bool GetInverted() const;
    
    	virtual void SetRadioButtonStyle(const bool bNewRadioButtonStyle = true);
    	virtual bool GetRadioButtonStyle() const;
    
    	virtual void SetDialColor(const COLORREF crBkgnd);
    	virtual void SetKnobColor(const COLORREF crBkgnd);
    	virtual void SetTextColor(const COLORREF crText);
    
    	virtual void SetFontBold(const bool bSet = true);
    	virtual void SetFontUnderline(const bool bSet = true);
    	virtual void SetFontItalic(const bool bSet = true);
    	virtual void SetFontSize(const int nSize);
    	virtual void SetFontName(const CString& strFont);
    

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    Share

    About the Author

    Daniel Frey

    Germany Germany
    No Biography provided

    Comments and Discussions

     
    Generalproblem in DrawCircle Pin
    damien_polytech26-Sep-10 23:09
    memberdamien_polytech26-Sep-10 23:09 
    GeneralVerifyPos() no longer supported in MFC Pin
    merano4-Jun-10 0:17
    membermerano4-Jun-10 0:17 
    GeneralThank you Pin
    futurejo13-Jan-09 4:33
    memberfuturejo13-Jan-09 4:33 
    GeneralExecellent Class Works great , Pin
    ScotDolan27-Jun-07 12:46
    memberScotDolan27-Jun-07 12:46 
    GeneralCongratulations Pin
    Svetoslav Chekanov17-Dec-04 3:54
    memberSvetoslav Chekanov17-Dec-04 3:54 
    QuestionHow to make it transparent ? Pin
    visualobeje1-Dec-03 10:32
    membervisualobeje1-Dec-03 10:32 
    QuestionHow to colour the slider? Pin
    visualobeje23-Nov-03 7:07
    membervisualobeje23-Nov-03 7:07 
    QuestionHow to create round slider dynamically? Pin
    Ejaz8-Oct-03 0:13
    memberEjaz8-Oct-03 0:13 
    AnswerRe: How to create round slider dynamically? Pin
    wflishh7-May-11 3:07
    memberwflishh7-May-11 3:07 
    GeneralCan't get NM_RELEASEDCAPTURE Pin
    Suha Aktan10-Jun-03 23:23
    memberSuha Aktan10-Jun-03 23:23 
    GeneralLock mouse cursor Pin
    Synetech18-Feb-03 9:10
    memberSynetech18-Feb-03 9:10 
    GeneralBugFix: Lost focus while dragging... Pin
    Michael Stammberger5-Mar-02 4:47
    memberMichael Stammberger5-Mar-02 4:47 
    GeneralA doubt..... Pin
    Rejeesh.T.S25-Jul-01 1:44
    memberRejeesh.T.S25-Jul-01 1:44 
    GeneralVery well done!!! Pin
    Krakhead15-Sep-00 4:53
    sussKrakhead15-Sep-00 4:53 

    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
    Web01 | 2.8.150520.1 | Last Updated 17 Mar 2000
    Article Copyright 2000 by Daniel Frey
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid