Search
Diagram Class
Remarks See Also
 





Represents a flow diagram.

Namespace: MindFusion.Diagramming
Package: MindFusion.Diagramming

 Syntax

C#  Copy Code

public class Diagram : DiagramBase, IItemFactory, IPersists

Visual Basic  Copy Code

Public Class Diagram
    Inherits DiagramBase
    Implements IItemFactory, IPersists

 Remarks

An instance of the Diagram class represents a diagram document. A Diagram instance does not provide its own user interface. To display a diagram on a form, add a DiagramView instance to the form and set the view's Diagram property. A diagram can be displayed in more than one view.

A diagram can contain connected nodes and links. Nodes are instances of DiagramNode-derived classes. Nodes are stored in the Nodes collection. Links in NetDiagram are instances of the DiagramLink class and are stored in the Links collection. Diagram items can be grouped in hierarchical structures and the so formed groups can be accessed by means of the Groups collection.

Managing Items

Items can be created by using the new operator and added to the diagram by means of the Add method of the Nodes or Links collection. Items are deleted by using the Remove method of the respective collection. There are shortcut methods provided by the diagram's Factory object that can be used to create an item and add it to the diagram with just one method call. Use the CreateTableNode, CreateShapeNode and CreateDiagramLink factory methods to create new items of the respective type.

Hierarchical groups of items are created by adding a Group instance to the diagram's Groups collection. The Factory object provides a shortcut CreateGroup method to do that with a single method call. Use the Remove method of the Groups collection to destroy a group.

Searching for a particular kind of items is done with the FindLink, FindNode and FindGroup methods, which look for an item that has a particular Tag, or FindLinkById and FindNodeById to find items by their Id. To get the item placed at a certain location, use the GetItemAt method.

Serialization

Binary serialization of diagrams is provided by the SaveToStream and LoadFromStream methods which serialize diagrams to / from .NET streams. SaveToFile and LoadFromFile wrap their stream counterparts to implement easy serialization to disk files. SaveToString and LoadFromString store or load diagrams to/from ASCII strings, allowing easy storage of whole diagrams in a database or their transfer between a web-server and a browser through a hidden html element.

Use the SaveToXml and LoadFromXml methods to serialize a diagram into/from XML documents.

Controlling Users' Actions

Most aspects of user interaction are controlled by the DiagramView class.

Users actions can be validated by handling various events, fired while items are being created, modified or deleted.

The following properties control what kind of links users can create: AllowLinksRepeat, AllowSelfLoops, AllowUnanchoredLinks, AllowUnconnectedLinks.

The order in which items are hit-tested when clicking on them depends on the value of HitTestPriority. The LinkHitDistance property specifies the furthest distance from a link that a click would be still considered a hit.

Alignment

Items are aligned to a grid when AlignToGrid is enabled. To display the grid, set ShowGrid to true. The grid size and appearance can be customized via the GridSizeX, GridSizeY, GridColor and GridStyle properties.

If AutoAlignNodes is enabled, nodes are aligned to other nodes so that a pair of their vertical or horizontal sides become collinear. To specify the maximal distance at which nodes are aligned, set the AutoAlignDistance property. The pair of aligned nodes is indicated visually by drawing an alignment guide using the pen assigned to AlignmentGuidePen.

Links can also automatically snap to nodes when AutoSnapLinks is set. The maximal distance at which links will connect to a nearby node is set via AutoSnapDistance.

Appearance

The Diagram background area can be painted using a solid, gradient, texture or color brush, by setting the BackBrush property, and/or using an image specified by BackgroundImage and BackgroundImageAlign. Some more elaborate visual effects can be applied by means of the EffectsProvider, EnableEmbossEffects and EnableShadowEffects properties.

To further customize the diagram appearance, handle the DrawBackground event to render custom background graphics, or the DrawForeground event to render custom foreground graphics.

Lanes

The lane grid lets you emphasize the relationship between a group of diagram items by displaying them in a distinct lane or cell within the grid. Use the EnableLanes property to display a background grid of lanes, optionally divided into cells. The grid can be set up using the LaneGrid property.

Text Formatting

Use TextFormat and TextColor to specify alignment and color of the text for all diagram items. EnableStyledText allows using HTML-like tags to format item's text. PolygonalTextLayout allows laying text out inside non-rectangular node shapes.

Tweaks

  • While moving grouped items, they are drawn in depth conforming to either their z-order or their group hierarchy, as set in SortGroupsByZ.
  • SelectionOnTop specifies whether selected items should be painted on top of other items.
  • MergeThreshold specifies how closely one to another adjacent link points should be placed in order to merge link segments.

Default Item Properties

Many properties of the Diagram class provide initial values for the properties of new items.

 Inheritance Hierarchy

System.Object
    System.MarshalByRefObject
        System.ComponentModel.Component
            MindFusion.Diagramming.DiagramBase
                MindFusion.Diagramming.Diagram
                    MindFusion.Diagramming.DiagramPage

 See Also