Click here to Skip to main content
15,886,199 members
Articles / Desktop Programming / MFC
Article

A Ruler Control

Rate me:
Please Sign up or sign in to vote.
3.00/5 (1 vote)
7 Feb 2000 93.8K   1.9K   28   8
A simple ruler control to allow users to set margins or indents
  • Download source files - 21 Kb
  • Sample Image - RulerCtrl.jpg

    Introduction

    CRulerSlider is a control derived from CProgressCtrl. The Control replicates the behaviour of the ruler bar in many wordprocessor applications, and allows the user to click and drag the left and right edges to set values for such things as margins and indents. The code for the control is in the RulerSlider.cpp and RulerSlider.h files.

    To use...

    Using the control is as simple as using any other derived control. Simply place a progress control onto a dialog or form and subclass is using the Wizards. Alternatively, you can create the control dynamically. For example:

    CRect rc = CRect(10,80,300, 100); 
    CRulerSlider slider;
    slider.Create(WS_CHILD|WS_VISIBLE|PBS_SMOOTH| WS_TABSTOP , rc, this, 2); 

    The control has only two properties:

    int GetLeftPos()
    int GetRightPos()

    These get the size of the left and right margins (always greater than or equal to 0).

    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


    Written By
    Netherlands Netherlands
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    General[Help] Transforming this ruler control [modified] Pin
    Mancini26-Dec-07 4:56
    Mancini26-Dec-07 4:56 
    QuestionCan a graph scale be based on your ruler Pin
    31-Dec-01 13:52
    suss31-Dec-01 13:52 
    We only need a non-interactive scale for a vertical graph. I was wondering if some of the code in the Ruler class could be borrowed for our needs. Some problems that I am expecting are listed below:

    1. We do not want tick marks colliding. If the settings call for 30 tick marks, but we have room for only 20, we need to skip some.

    2. If the labels for the visible tick marks would collide, we need to hide some labels (not the tick marks themselves) as needed to ensure that the labels are readable.

    3. We want to round the distance (in logical units) between tick marks to at least whole numbers. This helps to establish a pattern in the tick mark labels. (So that each label is, say, 20 more that that of the previous label.) The larger the numbers that are shown in the tick mark labels, the more that we would want to round the numbers. So if the scale is showing values from 0 to 20, integers would suffice. But if the scale is showing values from 0 to 1000, it would make sense to show only values that are as accurate as could be shown (taking into account the number of requested tick marks as well as Rules 1 and 2).

    4. We may need to size the scale window position according to the screen size. This would depend on what mode the program is in. The mode in question requires the program compensate for a rocking boat by making everything bigger (we replace the Windows look and feel with seperate windows that implement their own). This require also means that the scale can not be a window in the true sense. Rather the "parent" window would pass its DC to paint the scale.

    ----------------------------------------------------
    Thank you for any help that you can provide.

    Will Pittenger
    GeneralProblem in Init(const CRect rect) Pin
    5-Dec-01 21:43
    suss5-Dec-01 21:43 
    GeneralDividing the ruler control Pin
    JCY27-Sep-01 9:14
    JCY27-Sep-01 9:14 
    GeneralProgress Control Pin
    JekYu30-Aug-01 14:14
    JekYu30-Aug-01 14:14 
    GeneralThe code doesn't work. Pin
    5-Nov-00 17:49
    suss5-Nov-00 17:49 
    GeneralRe: The code doesn't work. Pin
    Christian Graus5-Nov-00 22:16
    protectorChristian Graus5-Nov-00 22:16 
    Questionhorizontal, yes - but vertical? Pin
    Frédéric Marion-Poll16-Aug-00 2:38
    sussFrédéric Marion-Poll16-Aug-00 2:38 

    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.