Export (0) Print
Expand All

FormattedText Constructor (String, CultureInfo, FlowDirection, Typeface, Double, Brush)

Initializes a new instance of the FormattedText class with the specified text, culture, flow direction, typeface, font size, and brush.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)

public FormattedText(
	string textToFormat,
	CultureInfo culture,
	FlowDirection flowDirection,
	Typeface typeface,
	double emSize,
	Brush foreground
)

Parameters

textToFormat
Type: System.String

The text to be displayed.

culture
Type: System.Globalization.CultureInfo

The specific culture of the text.

flowDirection
Type: System.Windows.FlowDirection

The direction the text is read.

typeface
Type: System.Windows.Media.Typeface

The font family, weight, style and stretch the text should be formatted with.

emSize
Type: System.Double

The font size the text should be formatted at.

foreground
Type: System.Windows.Media.Brush

The brush used to paint the each glyph.

The following example shows how to draw text to a DrawingVisual using a DrawingContext object. A drawing context is returned by calling the RenderOpen method of a DrawingVisual object. You can draw graphics and text into a drawing context.

To draw text into the drawing context, use the DrawText method of a DrawingContext object. When you are finished drawing content into the drawing context, call the Close method to close the drawing context and persist the content.

// Create a DrawingVisual that contains text. 
private DrawingVisual CreateDrawingVisualText()
{
    // Create an instance of a DrawingVisual.
    DrawingVisual drawingVisual = new DrawingVisual();

    // Retrieve the DrawingContext from the DrawingVisual.
    DrawingContext drawingContext = drawingVisual.RenderOpen();

    // Draw a formatted text string into the DrawingContext.
    drawingContext.DrawText(
       new FormattedText("Click Me!",
          CultureInfo.GetCultureInfo("en-us"),
          FlowDirection.LeftToRight,
          new Typeface("Verdana"),
          36, System.Windows.Media.Brushes.Black),
          new System.Windows.Point(200, 116));

    // Close the DrawingContext to persist changes to the DrawingVisual.
    drawingContext.Close();

    return drawingVisual;
}
NoteNote

For the complete code sample from which the preceding code example was extracted, see Hit Test Using DrawingVisuals Sample.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft