Search
Hosting .NET Controls in Nodes

A ControlNode instance can host any .NET control derived from System.Windows.Forms.Control. This allows you to use ready-made controls to display or edit the entities represented in your application's diagrams. The controls hosted in MindFusion.Diagramming nodes might be interactive and with embedded user interface. For example you might utilize calendars, grids, rich-text controls or html-pages as entity editors or viewers. You might also create your own custom control and integrate it seamlessly with MindFusion.Diagramming; as a result you can get as advanced entity-relationship diagram editor as your application needs.

Creating Controls Interactively

To allow end-users to draw ControlNode objects with the mouse, set Behavior to either DrawControls or LinkControls. The type of controls to be created in the host nodes is specified via the DefaultControlType property of DiagramView. If the following code executes, each node drawn by users would host a DataGrid instance, and nodes could be connected by drawing links between them:

C#  Copy Code

// Draw datagrid nodes and allow connecting them with links
diagramView.Behavior = Behavior.LinkControls;
 
// Default type of hosted controls is DataGrid
diagramView.DefaultControlType = typeof(DataGrid);

// Mouse clicks on hosted controls are processed by MindFusion.Diagramming
diagramView.ControlMouseAction = ControlMouseAction.IgnoreControl;

Visual Basic  Copy Code

' Draw datagrid nodes and allow connecting them with links
diagramView.Behavior = Behavior.LinkControls

' Default type of hosted controls is DataGrid
diagramView.DefaultControlType = GetType(DataGrid)

' Mouse clicks on hosted controls are processed by MindFusion.Diagramming
diagramView.ControlMouseAction = ControlMouseAction.IgnoreControl

Creating a ControlNode Programmatically

To create a ControlNode programmatically, add an instance of the class to the diagram's Nodes collection and set its Control property to an instance of a Control-derived class. A hosted control can be replaced with another one by assigning to Control again.

Consequences

Hosted controls are like any other child controls in a form, which leads to the following consequences:

  • they participate in the form's tab order;
  • they paint themselves in their own windows and are always drawn above other diagram items, independently of ZIndex;
  • they paint themselves in their own windows and MindFusion.Diagramming cannot always invoke their painting code, for example when printing or rendering preview/overview windows. Handle the PaintControl in situations where controls are not rendered properly;