Nevron .NET Vision Documentation
Labels

Labels are styleable elements, which display text. They can be anchored to specific aspects of the shape to which they belong, or to any of the models the shape aggregates. The labels of a shape are contained in an instance of the NLabelCollection class, which can be obtained from the Labels property of the shape. Labels are one of the optional shape elements and may not be available by default for each shape (see Shapes for more information).

All types of labels derive from the base NLabel class. Labels use the following class hierarchy:

All types of labels share the following set of features:

Label Text and Anchor Model

The text displayed by a label is controlled by the Text property. For example:

C#
Copy Code
label.Text = "My first label";
Visual Basic
Copy Code
label.Text = "My first label"

The model to which the label is anchored is specified by the AnchorUniqueId property. In case this property is equal to Guid.Empty the label is by default considered anchored to the shape to which it belongs. You can obtain a reference to the anchor model with the help of the GetAnchorModel method.

Currently Available Labels

The following table summarizes the currently available types of labels:

Label class Description
NBoundsLabel Represents a label, which is anchored to the scene bounds of a model. You can control the label margins (in percents relative to the anchor model scene bounds). The displayed text can be wrapped or stretched.

NRotatedBoundsLabel

Represents a label, which is anchored to the rotated bounds of a model. You can control the label margins (in percents relative to the anchor model rotated bounds). The displayed text can be wrapped or stretched.
NLogicalLineLabel Represents a label, which can be anchored to the percent position along the logical line of a model. You can specify whether the label should retain upward orientation and whether it should follow the logical line orientation at the specified percent.
NSegmentLabel Represents a label, which can be anchored to the percent position along the segment of a model. You can specify whether the label should retain upward orientation and whether it should follow the segment orientation at the specified percent. It also provides support for predefined (first, last, middle) and custom segment anchoring.
Default Label and Shape Text

Of all labels, which can reside in the labels collection of a shape one is considered as the default one (primary label). The default label is specified by the DefaultLabelUniqueId property of the NLabelCollection class and can be obtained from the DefaultLabel property. The following example adds a label to a shape and makes it the default one:

C#
Copy Code
// create the shape labels, if not already created
if (shape.Labels == null)
{
    shape.CreateShapeElements(ShapeElementsMask.Labels);
}

// create a rotated bounds label anchored to the shape
NRotatedBoundsLabel label = new NRotatedBoundsLabel("My first default label", shape.UniqueId, new NMargins(0));
shape.Labels.AddChild(label);
shape.Labels.DefaultLabelUniqueId = label.UniqueId;
Visual Basic
Copy Code
' create the shape labels, if not already created
If shape.Labels Is Nothing Then
    shape.CreateShapeElements(ShapeElementsMask.Labels)
End If

' create a rotated bounds label anchored to the shape
Dim label As New NRotatedBoundsLabel("My first default label", shape.UniqueId, New NMargins(0))
shape.Labels.AddChild(label)
shape.Labels.DefaultLabelUniqueId = label.UniqueId
By default the Text property of the NShape class, gets and set the text of the default label.
Related Examples
Windows Forms: Document Object Model - Shapes - Shape Labels
See Also

 

 


©2017. Nevron Software LLC.

Send Feedback