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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How can I add a custom property to the Diagram? How can I display the property in the Property Editor?


The sample included in this Knowledge Base article demonstrates how you can add a custom property to the Diagram and also display it in the the Property Editor. This sample uses a derived Diagram (MyDiagram) whose CreateModel method is overridden to use a derived Model (MyModel). MyModel’s SetDefaultPropertyValues is overridden to add the new MyCustomProperty property using the SetPropertyValue method. This property is displayed under a new category and also includes a description.

When you build and run the sample you can now see the new property (MyCustomProperty) in the Property Editor in the MyProperties category.

[C#] //Derived Diagram public class MyDiagram: Syncfusion.Windows.Forms.Diagram.Controls.Diagram {

 public override Model CreateModel()  {

  return new QuickStart.MainForm.MyModel();  } }

//Derived Model where the new property is added public class MyModel: Syncfusion.Windows.Forms.Diagram.Model {

 public override void SetDefaultPropertyValues()  {   base.SetDefaultPropertyValues ();   this.SetPropertyValue("MyCustomProperty", 0);

}  [  Browsable(true),  Category("MyProperties"),  Description("Description for MyCustomProperty")  ]  public int MyCustomProperty  {  get   {   object value = this.GetPropertyValue("MyCustomProperty");   if (value != null)    {

    return (int) value;


   return 0;   }  }


[VB.NET] //Derived Diagram Public Class MyDiagram         Inherits Syncfusion.Windows.Forms.Diagram.Controls.Diagram                 Public Overrides Function CreateModel() As Model                 Return New QuickStart.MainForm.MyModel()   End Function 'CreateModel     End Class

//Derived Model where the new property is added          Public Class MyModel         Inherits Syncfusion.Windows.Forms.Diagram.Model                         Public Overrides Sub SetDefaultPropertyValues()             MyBase.SetDefaultPropertyValues()             Me.SetPropertyValue("MyCustomProperty", 0)         End Sub 'SetDefaultPropertyValues                           _         Public ReadOnly Property MyCustomProperty() As Integer             Get                 Dim value As Object = Me.GetPropertyValue("MyCustomProperty")                 If Not (value Is Nothing) Then                                         Return Fix(value)                 End If                                 Return 0             End Get         End Property     End Class 'MyModel End Class

Article ID: Published Date: Last Revised Date: Platform: Control:
181 04/30/2011 07/10/2014 WinForms Diagram
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Please sign in to access our KB

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

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