Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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

Initializes a new instance of the FormattedText class.

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

public FormattedText (
	string textToFormat,
	CultureInfo culture,
	FlowDirection flowDirection,
	Typeface typeface,
	double emSize,
	Brush foreground
)
public FormattedText (
	String textToFormat, 
	CultureInfo culture, 
	FlowDirection flowDirection, 
	Typeface typeface, 
	double emSize, 
	Brush foreground
)
public function FormattedText (
	textToFormat : String, 
	culture : CultureInfo, 
	flowDirection : FlowDirection, 
	typeface : Typeface, 
	emSize : double, 
	foreground : Brush
)
You cannot use constructors in XAML.

Parameters

textToFormat

The text to be displayed.

culture

The specific culture of the text.

flowDirection

The direction the text is read.

typeface

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

emSize

The font size the text should be formatted at.

foreground

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 info 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, Brushes.Black),
          new 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 Using DrawingVisuals Sample.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2015 Microsoft