Articles in this section

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

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

 

Conclusion

I hope you enjoyed learning about how to add a custom property to the Diagram and display it in the Property Editor.

You can refer to WinForms Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Diagram example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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