Articles in this section
Category / Section

How do I create custom rulers for use in my Diagram?

2 mins read

How do I create custom rulers for use in my Diagram?

Essential Diagram uses two classes - Syncfusion.Windows.Forms.Diagram.HorizontalRuler and Syncfusion.Windows.Forms.Diagram.VerticalRuler - that derive from the base Syncfusion.Windows.Forms.Diagram.Ruler class for implementing the standard horizontal and vertical rulers. The Syncfusion.Windows.Forms.Diagram.View class that implements the diagram control's 'View' component hosts the two rulers and uses them for rendering the ruler gradations while drawing the diagram document.

To customize the diagram rulers, you will have to subclass one of the default ruler classes or the base Ruler type and implement the requisite drawing algorithm from an override of the Ruler.Draw(Graphics) method that is summoned by the View for drawing the ruler.

Once the custom ruler implementation is complete, the next step is to instruct your Diagram control instance to use this Ruler type. This is done by subclassing the Syncfusion.Windows.Forms.Diagram.View class used by the Diagram control, overriding the View's CreateHorizontalRuler()/CreateVerticalRuler() methods, and returning instances of your custom ruler types. The final step is to instruct the Diagram control instance to use this subclassed View type. This is done by overriding the Syncfusion.Windows.Forms.Diagram.Controls.Diagram control's Diagram.CreateView() method and returning the View subclass that uses your custom rulers. 

The appended schema of the HorizontalRuler class is a part of the 'Ruler.cs' file that ships with the Essential Diagram source version. Referring to this implementation should give you an idea of how to go about creating custom ruler types.

[C#]

/// Horizontal ruler draws hash marks left to right.  public class HorizontalRuler : Ruler {  public HorizontalRuler(View containerView, IPropertyContainer propContainer) : base(containerView, propContainer)  {  }
 protected override string PropertyPrefix  {   get{ return "HorizontalRuler"; }  }       public override System.Drawing.Rectangle Bounds  {
  get   {    System.Drawing.Rectangle value;    if(this.containerView != null)      value = this.containerView.HorizontalRulerBounds;    else      value = System.Drawing.Rectangle.Empty;    return value;   }  }
    /// Renders the ruler onto the graphics context.  public override void Draw(Graphics grfx)  { }
}   

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied