We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WinForms |
Control: Diagram

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.


/// 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)  { }


2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile