* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
1.9 KiB
title, ms.date, helpviewer_keywords, ms.assetid
| title | ms.date | helpviewer_keywords | ms.assetid | |||||
|---|---|---|---|---|---|---|---|---|
| How to: Draw Text to a Control's Background | 03/30/2017 |
|
686d8fba-f61c-4974-a871-c635d67a7f69 |
How to: Draw Text to a Control's Background
You can draw text directly to the background of a control by converting a text string to a xref:System.Windows.Media.FormattedText object, and then drawing the object to the control's xref:System.Windows.Media.DrawingContext. You can also use this technique for drawing to the background of objects derived from xref:System.Windows.Controls.Panel, such as xref:System.Windows.Controls.Canvas and xref:System.Windows.Controls.StackPanel.

Example of controls with custom text backgrounds
Example
To draw to the background of a control, create a new xref:System.Windows.Media.DrawingBrush object and draw the converted text to the object's xref:System.Windows.Media.DrawingContext. Then, assign the new xref:System.Windows.Media.DrawingBrush to the control's background property.
The following code example shows how to create a xref:System.Windows.Media.FormattedText object and draw to the background of a xref:System.Windows.Controls.Label and xref:System.Windows.Controls.Button object.
[!code-csharpDrawTextToControlBackground#DrawTextToControlBackground1]