Search
Using Components

The components in MindFusion.Diagramming are used through an instance of the CompositeNode class or a class deriving from CompositeNode. Simply create concrete component instances and add them to the Components collection of the CompositeNode.

Arranging Components

By default the composite node arranges its child components on top of each other, in the order they were added to the Components collection. To apply custom arrangement, the children should be organized in a component hierarchy using the appropriate panel components. For example, to arrange children horizontally, in a row, you can use the StackPanel with Orientation set to Horizontal. Here is an example on how to do this in code:

C#  Copy Code

CompositeNode node = new CompositeNode();

StackPanel panel = new StackPanel();
panel.Orientation = MindFusion.Diagramming.Components.Orientation.Horizontal;
panel.Spacing = 1;

TextComponent text = new TextComponent();
text.Text = "Hello world!";
panel.Components.Add(text);

ButtonComponent button = new ButtonComponent();
TextComponent buttonContent = new TextComponent();
buttonContent.Text = "Click me!";
button.Content = buttonContent;
panel.Components.Add(button);

node.Components.Add(panel);

Visual Basic  Copy Code

Dim node As New CompositeNode()

Dim panel As New StackPanel()
panel.Orientation = MindFusion.Diagramming.Components.Orientation.Horizontal
panel.Spacing = 1

Dim text As New TextComponent()
text.Text = "Hello world!"
panel.Components.Add(text)

Dim button As New ButtonComponent()
Dim buttonContent As New TextComponent()
buttonContent.Text = "Click me!"
button.Content = buttonContent
panel.Components.Add(button)

node.Components.Add(panel)

It is possible to create custom panel classes by deriving from ContentComponent and overriding the ArrangeComponents method. For an example on how to implement custom panel classes, check the Creating Custom Components topic.

Another way to arrange child components is by deriving from CompositeNode and overriding the ArrangeComponents method. Then, you can manually assign the position of individual nodes through their Bounds property.

Finding Components

The FindComponent method of the CompositeNode class can be used to search for components by their Name. This method performs a recursive search of all components in the Components collection and returns a reference to the first component with the specified name. This is particularly useful when the component hierarchy is defined through XML and you need to obtain a reference to a specific component in the hierarchy for additional processing. For more information on how to define components in XML check Components and XML.

Hit-testing Components

To retrieve the topmost component at a specific location, use the GetComponentAt method of the CompositeNode class. This method ignores components with any of the following properties set to false: IsEnabled, IsHitTestVisible.