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?

Platform: WinForms |
Control: Diagram |
Published Date: April 30, 2011 |
Last Revised Date: June 4, 2019

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

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
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