Draws the specified text within the specified bounds using the specified device context, font, color, back color, and formatting instructions.
- dc
- The device context in which to draw the text.
- text
- The text to draw.
- font
- The System.Drawing.Font to apply to the drawn text.
- bounds
- The System.Drawing.Rectangle that represents the bounds of the text.
- foreColor
- The System.Drawing.Color to apply to the text.
- backColor
- The System.Drawing.Color to apply to the area represented by bounds.
- flags
- A bitwise combination of the System.Windows.Forms.TextFormatFlags values.
The backcolor parameter is applied to the area within the bounds parameter. If font, forecolor or backcolor is null or System.Drawing.Color.Empty, respectively; the erload:System.Windows.Forms.TextRenderer.DrawText method will draw the text in the font or color currently selected in the device context specified by dc. If forecolor is System.Drawing.Color.Transparent, the text will not be drawn.
You can manipulate how the text is drawn by using one of the TextRenderer.DrawText(System.Drawing.IDeviceContext, string, System.Drawing.Font, System.Drawing.Rectangle, System.Drawing.Color, TextFormatFlags) overloads that takes a System.Windows.Forms.TextFormatFlags parameter. For example, the default behavior of the System.Windows.Forms.TextRenderer is to add padding to the bounding rectangle of the drawn text to accommodate overhanging glyphs. If you need to draw a line of text without these extra spaces you should use the versions of TextRenderer.DrawText(System.Drawing.IDeviceContext, string, System.Drawing.Font, System.Drawing.Point, System.Drawing.Color) and TextRenderer.MeasureText(System.Drawing.IDeviceContext, string, System.Drawing.Font) that take a System.Drawing.Size and System.Windows.Forms.TextFormatFlags parameter. For an example, see TextRenderer.MeasureText(System.Drawing.IDeviceContext, string, System.Drawing.Font, System.Drawing.Size, TextFormatFlags).
The text rendering offered by the System.Windows.Forms.TextRenderer class is based on GDI text rendering and is not supported for printing from Windows Forms. Instead, use the erload:System.Drawing.Graphics.DrawString methods of the System.Drawing.Graphics class.
The System.Windows.Forms.TextRenderer does not support adding tab stops to drawn text, although you can expand existing tab stops using the TextFormatFlags.ExpandTabs flag.