Table of Contents

Class TextBlock

Namespace
Northwoods.Go
Assembly
Northwoods.GoDiagram.WinForms.dll

A TextBlock is a GraphObject that displays a Text string in a given Font.

public class TextBlock : GraphObject, IHasContextMenu, IHasToolTip
Inheritance
TextBlock
Implements
Inherited Members

Remarks

The size and appearance of the text is specified by Font.

Text is drawn using the Stroke brush, which may be any CSS color string or a Brush.

A created TextBlock:

// A TextBlock with text and stroke properties set:
new TextBlock("Hello World") { Stroke = "gray" }

TextBlocks typically receive a natural size based on their text and font strings, but often a width is given in order to cause the text to wrap at a certain place. In order for wrapping to occur, the Wrap property must not be None.

TextBlocks can be edited by users using the TextEditingTool. The IHostInfo that a given TextBlock uses as its text editor can be customized by setting the TextEditor property.

For examples of TextBlock possibilities and functionality, see the Introduction page on TextBlocks.

Constructors

TextBlock()

Constructs a new TextBlock with no string to show; if it had a string, it would draw the text, wrapping if needed, in the default font using a black stroke.

public TextBlock()

TextBlock(string)

Constructs a new TextBlock with the given text string; draws the text, wrapping if needed, in the default font using a black stroke.

public TextBlock(string txt)

Parameters

txt string

Properties

Choices

Gets or sets the an array of possible choices for a custom TextEditingTool.

public IList<string> Choices { get; set; }

Property Value

IList<string>

Remarks

The value must be an array of strings.

The default value is null.

Editable

Gets or sets whether or not this TextBlock allows in-place editing of the Text string by the user with the help of the TextEditingTool.

public bool Editable { get; set; }

Property Value

bool

Remarks

The default is false.

See also TextEditable.

ErrorFunction

Gets or sets the function to call if a text edit made with the TextEditingTool is invalid.

public Action<TextEditingTool, string, string> ErrorFunction { get; set; }

Property Value

Action<TextEditingTool, string, string>

Remarks

The default is null.

Flip

Gets or sets how the TextBlock is displayed: Either normally or with a Horizontal or Vertical flip or both.

public Flip Flip { get; set; }

Property Value

Flip

Remarks

Possible values are None, Horizontal, Vertical, or Both. The default is None.

Font

Gets or sets the current font settings.

public Font Font { get; set; }

Property Value

Font

Remarks

The default font is new Font("Segoe UI", 13).

Formatting

Gets or sets the policy for trimming whitespace on each line of text.

public Format Formatting { get; set; }

Property Value

Format

Remarks

Possible values are Trim, which trims whitespace before and after every line of text, or None, which will not trim any whitespace and may be useful for preformatted text.

The default value is Trim.

See Also

GraduatedFunction

Gets or sets the function to convert from a value along a "Graduated" Panel to a string.

public Func<double, TextBlock, string> GraduatedFunction { get; set; }

Property Value

Func<double, TextBlock, string>

Remarks

The default returns a string representing the value rounded to at most 2 decimals.

The function takes a number argument, a value between GraduatedMin and GraduatedMax, and this TextBlock. The function will return a string, the text that will appear at the value of the argument.

Note that the second argument is not a particular label that would be rendered at the given value. The function, if supplied, must not have any side-effects.

GraduatedSkip

Gets or sets the function to determine which values along a "Graduated" Panel will be skipped.

public Func<double, GraphObject, bool> GraduatedSkip { get; set; }

Property Value

Func<double, GraphObject, bool>

Remarks

The default is null and doesn't skip any text labels.

The function takes a number argument, a value between GraduatedMin and GraduatedMax, and this TextBlock. The function will return a bool, whether the text label will be skipped at the value of the argument.

Note that the second argument is not a particular label that would be rendered at the given value. The function, if supplied, must not have any side-effects.

Interval

Gets or sets how frequently this text should be drawn within a "Graduated" Panel, in multiples of the GraduatedTickUnit.

public int Interval { get; set; }

Property Value

int

Remarks

The default is 1. Any new value must be a positive integer.

IsMultiline

Gets or sets whether or not the text displays multiple lines or embedded newlines.

public bool IsMultiline { get; set; }

Property Value

bool

Remarks

If this is false, all characters including and after the first newline will be omitted. The default is true.

See Also

IsStrikethrough

Gets or sets whether or not the text has a strikethrough line (line-through).

public bool IsStrikethrough { get; set; }

Property Value

bool

Remarks

The default is false.

See Also

IsUnderline

Gets or sets whether or not the text is underlined.

public bool IsUnderline { get; set; }

Property Value

bool

Remarks

The default is false.

See Also

LineCount

This read-only property returns the total number of lines in this TextBlock, including lines created from embedded newlines (\n), Wrapping, and MaxLines.

public int LineCount { get; }

Property Value

int

Remarks

This value may be meaningless before the TextBlock is measured.

See Also

LineHeight

This read-only property returns the height of a line of text in this TextBlock, not including any Northwoods.Go.TextBlock.SpacingAbove or Northwoods.Go.TextBlock.SpacingBelow.

public double LineHeight { get; }

Property Value

double
See Also

MaxLines

Gets or sets the maximum number of lines that this TextBlock can display.

public int MaxLines { get; set; }

Property Value

int

Remarks

Value must be a greater than zero whole number or int.MaxValue. The default is int.MaxValue.

Modifying this value may modify the computed height of the TextBlock. If MaxLines is set, the value of LineCount will never be larger than MaxLines.

See Also

NaturalBounds

This read-only property returns the natural bounds of this TextBlock in local coordinates, as determined by its Font and Text string, and optionally its DesiredSize.

public override Rect NaturalBounds { get; }

Property Value

Rect

Overflow

Gets or sets how text that is too long to display should be handled.

public Overflow Overflow { get; set; }

Property Value

Overflow

Remarks

Possible values are Clip and Ellipsis. For OverflowEllipsis to work, you must constrain the available size of the TextBlock in some way, such as setting Wrap to None, or limiting the number of lines with MaxLines or a height constraint.

The default value is Clip.

See Also

Stroke

Gets or sets the Brush that describes the stroke (color) of the text that is drawn.

public Brush Stroke { get; set; }

Property Value

Brush

Remarks

The default value is a solid black brush. Any valid CSS string can specify a solid color, and the Brush class can be used to specify a gradient or pattern. More information about the syntax of CSS color strings is available at: CSS colors (mozilla.org).

Text

Gets or sets the TextBlock's text string.

public string Text { get; set; }

Property Value

string

Remarks

The default is an empty string. The text of a TextBlock, along with the values of Font, Wrap, IsMultiline and sizing restrictions are what naturally determine the size of the TextBlock.

The text in textblocks can include manual line-breaks by using the character escape, \n.

Leading and trailing whitespace is eliminated in each line of TextBlock text.

If Editable is set to true, users can edit textblocks with the TextEditingTool.

TextAlign

Gets or sets the alignment location in the TextBlock's given space.

public TextAlign TextAlign { get; set; }

Property Value

TextAlign

Remarks

Possible values are Start, End, Left, Right, Center.

This property is most pertinent when the TextBlock has multiple lines of text, or when the TextBlock is given a size that differs from the text's natural size (such as with DesiredSize).

In left-to-right writing systems, Start and Left are synonymous, as are End and Right.

The default is Start.

See Also

TextEdited

Gets or sets the function that is called after the TextBlock's text has been edited by the TextEditingTool.

public Action<TextBlock, string, string> TextEdited { get; set; }

Property Value

Action<TextBlock, string, string>

Remarks

The first argument is a reference to this TextBlock. The second argument is the previous text, before editing. The third argument is the current text, which is also TextBlock.Text.

(textBlock, previousText, currentText) => { ... }

The default value is null -- no function is called.

TextEditor

Gets or sets the IHostInfo that this TextBlock uses as its text editor in the TextEditingTool.

public IHostInfo TextEditor { get; set; }

Property Value

IHostInfo

Remarks

If null, the TextBlock will use the default text editor of the TextEditingTool. The default is null. The value should be set to an instance of IHostInfo. Setting this property might not affect any ongoing text editing operation.

TextValidation

Gets or sets the predicate that determines whether or not a user-edited string of text is valid.

public Func<TextBlock, string, string, bool> TextValidation { get; set; }

Property Value

Func<TextBlock, string, string, bool>

Remarks

If this is non-null, the predicate is called in addition to any TextValidation predicate. See IsValidText(TextBlock, string, string) for more details.

(textBlock, oldString, newString) => { // return bool }

The default predicate is null, which is equivalent to simply returning true.

The function, if supplied, must not have any side-effects, and must return true or false.

See Also

VerticalAlignment

Gets or sets the vertical alignment Spot of this TextBlock, used when the TextBlock has more available vertical space than it needs to draw all lines.

public Spot VerticalAlignment { get; set; }

Property Value

Spot

Remarks

The default value is Top, which aligns the TextBlock to the top of its available space.

The TextAlign is often used along with this property to specify where the should be positioned in its available space.

This does not affect TextBlock coordinates or bounds, it only affects where text is drawn within the given area.

See Also

Wrap

Gets or sets whether the text should be wrapped if it is too long to fit on one line.

public Wrap Wrap { get; set; }

Property Value

Wrap

Remarks

Possible values are DesiredSize, Fit, BreakAll, and None.

The default value is DesiredSize.

See Also

Methods

GetBaseline()

Gets the function that, given the TextBlock and numerical text height, computes the position to draw the baseline of a line of text in all TextBlocks.

public static Func<TextBlock, double, double> GetBaseline()

Returns

Func<TextBlock, double, double>

Remarks

By default this is null and default behavior returns (textHeight * 0.75).

This computation affects drawing only, and does not change TextBlock measurement calculations.

GetUnderline()

Gets the function that, given the TextBlock and numerical text height, computes the position to draw the underline of a line of text in all TextBlocks.

public static Func<TextBlock, double, double> GetUnderline()

Returns

Func<TextBlock, double, double>

Remarks

By default this is null and default behavior returns (textHeight * 0.75).

This computation affects drawing only, and does not change TextBlock measurement calculations.

SetBaseline(Func<TextBlock, double, double>)

Sets the function that, given the TextBlock and numerical text height, computes the position to draw the baseline of a line of text in all TextBlocks.

public static void SetBaseline(Func<TextBlock, double, double> value)

Parameters

value Func<TextBlock, double, double>

Remarks

This computation affects drawing only, and does not change TextBlock measurement calculations. It is expected this method will be called before or during initialization of any Diagram. Diagrams will not redraw when this method has been called, and you should call Diagram.Redraw() if you are calling this method outside of your initialization.

SetUnderline(Func<TextBlock, double, double>)

Sets the function that, given the TextBlock and numerical text height, computes the position to draw the underline of a line of text in all TextBlocks.

public static void SetUnderline(Func<TextBlock, double, double> value)

Parameters

value Func<TextBlock, double, double>

Remarks

This computation affects drawing only, and does not change TextBlock measurement calculations. It is expected this method will be called before or during initialization of any Diagram. Diagrams will not redraw when this method has been called, and you should call Diagram.Redraw() if you are calling this method outside of your initialization.