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 do I sub-class the model, view, and controller classes?

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

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
 

 

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