在指定位置繪制格式化文本。
命名空間: System.Windows.Media
程序集: PresentationCore(在 PresentationCore.dll 中)
參數
- formattedText
- 類(lèi)型:System.Windows.Media.FormattedText
要繪制的格式化文本。
- origin
- 類(lèi)型:System.Windows.Point
要繪制文本的位置。
| 異常 | 條件 |
|---|---|
| ObjectDisposedException | 該對象已被關(guān)閉或釋放。 |
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;}

