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