Search
Creating and Deleting Items

Creating Items Programmatically

In order to add a new node or link to a diagram, create an instance of the item class via the new operator and add it to the diagram's Nodes or Links collection. This works the same way for adding both items from your custom class or ones from the MvcDiagram predefined types.

There are several shortcut methods provided for creating instances of the predefined node and link types. The methods are members of the diagram's Factory object:

Drawing New Items

Users can draw diagram elements with the mouse. This creates either a node or a link, depending on whether there is already another diagram item under the mouse cursor. When a user starts drawing, an item is created and its appearance is initialized from the default-value properties of the Diagram, such as ShapePen and ShapeBrush. When the user releases the mouse button, the item is added to the collection that contains items from the same type - either Nodes or Links.

Deleting Items

Call the Remove method of the Nodes or Links collection to delete an item from the diagram. The ClearAll method clears diagram contents by deleting all items.