This documentation is archived and is not being maintained.

DrawingContext.DrawText Method

Draws formatted text at the specified location.

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

Public Sub DrawText ( _
	formattedText As FormattedText, _
	origin As Point _
Dim instance As DrawingContext 
Dim formattedText As FormattedText 
Dim origin As Point

instance.DrawText(formattedText, origin)
You cannot use methods in XAML.


Type: System.Windows.Media.FormattedText

The formatted text to be drawn.

Type: System.Windows.Point

The location where the text is to be drawn.


The object has already been closed or disposed.

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.
       new FormattedText("Click Me!",
          new Typeface("Verdana"),
          36, System.Windows.Media.Brushes.Black),
          new System.Windows.Point(200, 116));

    // Close the DrawingContext to persist changes to the DrawingVisual.

    return drawingVisual;

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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5, 3.0