How do I sub-class the model, view, and controller classes?
How do I sub-class the model, view, and controller classes?
Creating derived model, view, and controller classes is a very useful technique for highly-specialized diagramming applications. For example, you might want to sub-class the model if the content of your diagrams is generated by or synchronized with data managed by your application. Sub-classing the controller is useful when you want to customize the diagramming user-interface.
Creating a new class derived from the model, view, and controller classes is very easy. Just write a new class and declare the model, view, or controller as the base class. You can override virtual methods in your derived classes and add new methods and properties.
The code below shows derived model, view, and controller classes:
C#
using Syncfusion.Windows.Forms.Diagram; using Syncfusion.Windows.Forms.Diagram.Controls; // Derived Diagram Model class [Serializable()] public class MyModel : Syncfusion.Windows.Forms.Diagram.Model { public MyModel() {} // Serialization constructor protected MyModel(SerializationInfo info, StreamingContext context):base(info, context) {} } // Derived Diagram View class [Serializable()] public class MyView : Syncfusion.Windows.Forms.Diagram.View { public MyView() {} // Serialization constructor protected MyView(SerializationInfo info, StreamingContext context):base(info, context) {} } // Derived Diagram Controller class public class MyController : Syncfusion.Windows.Forms.Diagram.DiagramController { public MyController() {} }
VB
Imports Syncfusion.Windows.Forms.Diagram Imports Syncfusion.Windows.Forms.Diagram.Controls ' Derived Model Public Class MyModel Inherits Syncfusion.Windows.Forms.Diagram.Model Public Sub New() End Sub ' Serialization constructor Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext) MyBase.New(info, context) End Sub 'New End Class ' Derived View class Public Class MyView Inherits Syncfusion.Windows.Forms.Diagram.View Public Sub New() End Sub ' Serialization constructor Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext) MyBase.New(info, context) End Sub 'New End Class ' Derived Controller class Public Class MyController Inherits Syncfusion.Windows.Forms.Diagram.DiagramController Public Sub New() End Sub End Class
The next step is to have the Diagram control use your new model, view, and controller classes. You must sub-class the Diagram control and override the CreateModel, CreateView, and CreateController methods.
C#
// Diagram control subclass public class MyDiagramControl : Syncfusion.Windows.Forms.Diagram.Controls.Diagram { public MyDiagramControl() { } public override Syncfusion.Windows.Forms.Diagram.Model CreateModel() { return new MyModel(); } public override Syncfusion.Windows.Forms.Diagram.View CreateView() { return new MyView(); } public override Syncfusion.Windows.Forms.Diagram.Controller CreateController() { return new MyController(); } }
VB
' Diagram control subclass Public Class MyDiagram Inherits Syncfusion.Windows.Forms.Diagram.Controls.Diagram Public Sub New() End Sub Public Overrides Function CreateModel() As Syncfusion.Windows.Forms.Diagram.Model Return New MyModel End Function Public Overrides Function CreateView() As Syncfusion.Windows.Forms.Diagram.View Return New MyView End Function Public Overrides Function CreateController() As Syncfusion.Windows.Forms.Diagram.Controller Return New MyController End Function End Class
Conclusion
I hope you enjoyed learning about how to sub-class the model, view, and controller classes.
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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!