Diagram for .NET / User's Guide / WinForm Components / Rulers

In This Topic
    Rulers
    In This Topic

    Each view has two rulers - horizontal and vertical, which are represented by instances of the NHorizontalRuler and NVerticalRuler classes respectively. They both derive from the base NRuler class (on its turn derived from NViewComponent).

    You can obtain a reference to the horizontal ruler via the HorizontalRuler property. Analogously a reference to the vertical ruler is obtained from the VerticalRuler property:

    C#
    Copy Code
    // get the horizontal and the vertical ruler
    NHorizontalRuler hruler = view.HorizontalRuler;
    NVerticalRuler vruler = view.VerticalRuler;
    
    Visual Basic
    Copy Code
    ' get the horizontal and the vertical ruler
    Dim hruler As NHorizontalRuler = view.HorizontalRuler
    Dim vruler As NVerticalRuler = view.VerticalRuler
    
     Ruler Appearance
    Rulers are displayed as framed rectangles on the top and left sides of the view window. The frame border color is controlled by the FrameColor property, while the ruler filling is controlled by the BackColor property. The size of each ruler can only be controlled in the dimension opposite to the ruler expand direction via the Size property (e.g. for the horizontal ruler the size is it's height). The offset of the view window from the ruler rim is called ruler padding and is controlled by the Padding property.
     Ruler Ticks

    Rulers display major and minor ticks. There is a fixed number of minor ticks displayed between two major ones, which is controlled by the MinorTicksCount property. The value from which the major ticks originate is called origin and is controlled by the Origin property and is specified in the ruler unit of measure.

    The step of the major ticks can be determined in several modes. The major ticks step mode is controlled by the MajorTicksStepMode property, which can accept one of the following values:

    • Fine - the ruler automatically chooses a relatively small step based on the current view scale (twice smaller than normal)
    • Normal - the ruler automatically chooses a relatively normal step based on the current view scale.
    • Coarse - the ruler automatically chooses a relatively large step based on the current view scale (twice larger than normal) 
    • Fixed - the ruler major tick step is constant and is specified by the FixedMajorTicksStep property.

      The following code makes a fixed ruler with major tick step 50 in the current ruler measurement unit and displays 6 minor ticks between the major ones.

    • C#
      Copy Code
      // change the major ticks step mode
      ruler.MajorTicksStepMode = AutoStepMode.Fixed;
      ruler.FixedMajorTicksStep = 50;
      
      // change the number of minor ticks
      ruler.MinorTicksCount = 6;
      
      Visual Basic
      Copy Code
      ' change the major ticks step mode
      ruler.MajorTicksStepMode = AutoStepMode.Fixed
      ruler.FixedMajorTicksStep = 50
      
      ' change the number of minor ticks
      ruler.MinorTicksCount = 6
      

      You can also control the minor ticks length as well as the major and minor ticks color with the help of the MinorTicksLength, MajorTicksColor and MinorTicksColor properties respectively.

     Ruler Texts

    Ruler texts are displayed for the values of the major ticks. Ruler texts are displayed with the font specified by the TextFontStyle property and with format defined by the TextFormat property. The text color is analogously controlled by the TextColor property. The following code alters the texts font, color and format:

    C#
    Copy Code
    // alter the ruler text font, color and format
    ruler.TextFontStyle = new NFontStyle("Tahoma", 10);
    ruler.TextColor = Color.Red;
    ruler.TextFormat = "0.##";
    
    Visual Basic
    Copy Code
    ' alter the ruler text font, color and format
    ruler.TextFontStyle = New NFontStyle("Tahoma", 10)
    ruler.TextColor = Color.Red
    ruler.TextFormat = "0.##"
    
     Related Examples
    Windows Forms: Drawing View - Rulers
    See Also