Diagram for .NET / User's Guide / Templates / Templates and Wizard

In This Topic
    Templates and Wizard
    In This Topic
    Templates are reusable programmable structures, which can be used to create DOM content. All templates must derive from the base NTemplate abstract class.
     Common template features

    Since all templates derive from the NTemplate base class they share the following set of common features: 

    • Attributes - NTemplate adds support for attributes (hence implements the INAttributeContainer and INAttributeObserver interface).
    • Measurement Unit - the template measurements are measured in the template measurement unit. That is why NTemplate implements the INMeasurementUnit, INResolution and INMeasurements interfaces.
    • Visual Configuration - in order to be visually configured with the wizard, templates must create user controls. They appear as tabs in the wizard tab control after the ever existing Select Template Tab. When a template is selected in the wizard, the wizard will call the template CreateUserControls method, which is responsible to return an array of the template user controls. The template user controls must be derived from the NTemplateUserControl base class.
    • TemplateChanged Event - the TemplateChanged event of the NTemplate class must always be fired when a property of the template has changed, since the wizard subscribes for this event in order to regenerate the template preview.

    You can instanciate any template in a document of your choice by calling its Create method.

    C#
    Copy Code
    // create the template
    NGenericTreeTemplate treeTemplate = new NGenericTreeTemplate();
    
    // modify its measurement unit to be the same as the document measurement unit
    treeTemplate.MeasurementUnit = document.MeasurementUnit;
    
    // modify the template properties
    ...
    
    // create it in the document
    treeTemplate.Create(document);
    
    Visual Basic
    Copy Code
    ' create the template
    Dim treeTemplate As New NGenericTreeTemplate
    
    ' modify its measurement unit to be the same as the document measurement unit
    treeTemplate.MeasurementUnit = document.MeasurementUnit
    
    ' modify the template properties
    ...
    
    ' create it in the document
    treeTemplate.Create(document)
    
     Currently available templates

    All currently available templates create their content in the current active layer of the document. The following table summarizes the currently available templates.

    Template class Description
    NFamilyTreeTemplate Represents a family tree template consisting of two parents and user controllable count of children
    NGenericTreeTemplate Represents a generic tree with user controllable count of levels and children
    NEllipticalGridTemplate Represents an elliptical graph with an optional center and user controllable connections
    NRectangularGridTemplate Represents a rectangular graph grid with user controllable connections
    NTriangularGridTemplate Represents a triangular graph grid with user controllable connections
    NRandomGraphTemplate Represents a connected random graph which number of edges and vertices are controlled by the EdgeCount and VertexCount properties
     Wizard

    The templates wizard provides a visual interface for template selection, modification and creation. It is represented by the NWizard class, which can be instanced on demand:

    C#
    Copy Code
    // create the wizard
    NWizard wizard = new NWizard(document);
    
    Visual Basic
    Copy Code
    ' create the wizard
    Dim wizard As New NWizard(document)
    

    The wizard maintains a collection of NTemplateCollection instances, which it treats as template categories. This way you can easily customize the wizard by removing any of the predefined categories or templates or creating your own categories. For example:

    C#
    Copy Code
    // remove the second category
    wizard.RemoveCategory(wizard.Categories[1]);
    
    // create a custom template and a category containing a user defined template
    NMyTemplate myTemplate = new NMyTemplate();
    NTemplateCollection myCategory = NTemplateCollection("My Category");
    myCategory.Add(myTemplate);
    
    // register this category in the wizard
    wizard.AddCategory(myCategory);
    
    Visual Basic
    Copy Code
    ' remove the second category
    wizard.RemoveCategory(wizard.Categories.GetValue(1))
    
    ' create a custom template and a category containing a user defined template
    Dim myTemplate As New NMyTemplate
    Dim myCategory As New NTemplateCollection("My Category")
    myCategory.Add(myTemplate)
    
    ' register this category in the wizard
    wizard.AddCategory(myCategory)
    

    The wizard is displayed with the ShowDialog method.

    C#
    Copy Code
    // show the wizard
    wizard.ShowDialog();
    
    Visual Basic
    Copy Code
    ' show the wizard
    wizard.ShowDialog()
    
     Related Examples
    Windows Forms: Visual Interface Components - Wizard
    See Also