Search
User Defined Shapes and Custom Drawing

The appearance of NetDiagram items can be customized in several additional ways, as described below.

Shape Templates

The Shape class provides the means for defining complex geometric shapes, made of straight lines, arcs and Bezier curves. Such shapes can be assigned to the Shape property of ShapeNode objects, or to the HeadShape property of DiagramLink objects. A shape template must always contain an outline to be used for hit testing, clipping and finding intersections with other items. Optionally shapes can contain decoration elements and text region definitions. Decorations are visual elements that do not take part in hit testing and clipping. Text regions are the parts of shapes in which node's text is laid-out and rendered. NetDiagram provides more than 100 predefined shape templates, which can be accessed via the Shapes collection or FromId method of the Shape class. Each predefined shape has a string identifier assigned to it. Use the FromId method to find a shape with the specified id.

Shape Libraries

The ShapeDesigner tool included in the NetDiagram suite lets you draw custom shapes and store them in shape libraries. A library file can be loaded into your application using the ShapeLibrary class. The definitions loaded from a shape library are automatically added to the Shapes collection and can be accessed through the FromId method, just as the predefined shapes.

Custom Painting

Another way to customize item's appearance is implemented by raising an event each time an item is painted, giving you the option to attach your own drawing code to the NetDiagram's rendering engine. Use the CustomDraw property of items to enable that feature in your application.
NetDiagram provides several options for custom drawing. If you choose Additional drawing style, your drawing code will be executed after the standard item drawing code is executed and Image is rendered, but before the text is rendered. Furthermore, the Graphics object you receive to draw on has a clipping region applied that corresponds to a node's shape. If using Full drawing mode, none of the standard NetDiagram drawing code is executed - just yours. The ShadowOnly mode performs standard painting of items, but leaves the drawing of shadows to your code.

Place your own drawing code in a handler of the DrawNode, DrawCell and DrawLink events. These events are fired for each custom-drawn item that needs repainting.

Combining Custom Shapes with Custom Drawing

Finally, you could combine user-defined shapes with the Additional custom-painting style. Thus, you can get custom shaping enabled for a node and your custom painting code executing with the node shape used as clipping region. You might clear the clipping region, but be careful - if you draw outside node's bounding rectangle, the view may not update correctly.