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.
Unfortunately, activation email could not send to your email. Please try again.

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

Article ID: Published Date: Last Revised Date: Platform: Control:
172 04/30/2011 07/10/2014 Windows Forms Diagram
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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.