textrenderer.drawtext是指使用指定的設備上下文、顏色和字體在指定位置繪制指定文本。
主要有:
DrawText(IDeviceContext, String, Font, Point, Color) | 使用指定的設備上下文、字體和顏色在指定位置繪制指定文本。 |
DrawText(IDeviceContext, String, Font, Rectangle, Color) | 使用指定的設備上下文、字體和顏色在指定界限中繪制指定文本。 |
DrawText(IDeviceContext, String, Font, Point, Color, Color) | 使用指定的設備上下文、字體、顏色和背景色在指定位置繪制指定文本。 |
DrawText(IDeviceContext, String, Font, Point, Color, TextFormatFlags) | 使用指定的設備上下文、字體、顏色和格式說明在指定位置繪制指定文本。 |
DrawText(IDeviceContext, String, Font, Rectangle, Color, Color) | 使用指定的設備上下文、字體、顏色和背景色在指定界限中繪制指定文本。 |
DrawText(IDeviceContext, String, Font, Rectangle, Color, TextFormatFlags) | 使用指定的設備上下文、字體、顏色和格式說明在指定界限中繪制指定文本。 |
DrawText(IDeviceContext, String, Font, Point, Color, Color, TextFormatFlags) | 使用指定的設備上下文、字體、顏色、背景色和格式說明在指定位置繪制指定文本。 |
DrawText(IDeviceContext, String, Font, Rectangle, Color, Color, TextFormatFlags) | 使用指定的設備上下文、字體、顏色、背景色和格式說明在指定界限中繪制指定文本。 |
DrawText(IDeviceContext, String, Font, Point, Color)
使用指定的設備上下文、字體和顏色在指定位置繪制指定文本。
public static void DrawText (System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Point pt, System.Drawing.Color foreColor);
參數
IDeviceContextdc 繪制文本所使用的設備上下文。
- text String 要繪制的文本。
示例
下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText1
,並將 e
作為 @no__t。
private void RenderText1(PaintEventArgs e)
{ TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font, new Point(10, 10), SystemColors.ControlText); }
DrawText(IDeviceContext, String, Font, Rectangle, Color)
使用指定的設備上下文、字體和顏色在指定界限中繪制指定文本。
public static void DrawText (System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor);
參數
- dc IDeviceContext 繪制文本所使用的設備上下文。
- text String 要繪制的文本。
異常
dc
為 null
。
示例
下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText2
,並將 e
作為 @no__t。
private void RenderText2(PaintEventArgs e)
{ TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font, new Rectangle(10, 10, 100, 100), SystemColors.ControlText); }
DrawText(IDeviceContext, String, Font, Point, Color, Color)
使用指定的設備上下文、字體、顏色和背景色在指定位置繪制指定文本。
public static void DrawText (System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Point pt, System.Drawing.Color foreColor, System.Drawing.Color backColor);
參數
- dc IDeviceContext 繪制文本所使用的設備上下文。
- text String 要繪制的文本。
異常
dc
為 null
。
示例
下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText3
,並將 e
作為 @no__t。
private void RenderText3(PaintEventArgs e) { TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font, new Point(10, 10), Color.Red, Color.PowderBlue); }
DrawText(IDeviceContext, String, Font, Point, Color, TextFormatFlags)
使用指定的設備上下文、字體、顏色和格式說明在指定位置繪制指定文本。
public static void DrawText (System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Point pt, System.Drawing.Color foreColor, System.Windows.Forms.TextFormatFlags flags);
參數
- dc IDeviceContext 繪制文本所使用的設備上下文。
- text String 要繪制的文本。
- flags TextFormatFlags TextFormatFlags 值的按位組合。
異常
dc
為 null
。
示例
下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText5
,並將 e
作為 @no__t。
private void RenderText5(PaintEventArgs e)
{ TextRenderer.DrawText(e.Graphics, "Some text.", this.Font, new Point(10, 10), SystemColors.ControlText, TextFormatFlags.Bottom); }
DrawText(IDeviceContext, String, Font, Rectangle, Color, Color)
使用指定的設備上下文、字體、顏色和背景色在指定界限中繪制指定文本。
public static void DrawText (System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor, System.Drawing.Color backColor);
參數
- dc IDeviceContext 繪制文本所使用的設備上下文。
- text String 要繪制的文本。
異常
dc
為 null
。
示例
下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText4
,並將 e
作為 @no__t。
private void RenderText4(PaintEventArgs e)
{ TextRenderer.DrawText(e.Graphics, "Regular Text.", this.Font, new Rectangle(10, 10, 70, 70), SystemColors.ControlText, SystemColors.ControlDark); }
DrawText(IDeviceContext, String, Font, Rectangle, Color, TextFormatFlags)
使用指定的設備上下文、字體、顏色和格式說明在指定界限中繪制指定文本。
public static void DrawText (System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor, System.Windows.Forms.TextFormatFlags flags);
參數
- dc IDeviceContext 繪制文本所使用的設備上下文。
- text String 要繪制的文本。
- flags TextFormatFlags TextFormatFlags 值的按位組合。
異常
dc
為 null
。
示例
下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText6
,並將 e
作為 @no__t。
private void RenderText6(PaintEventArgs e)
{ TextFormatFlags flags = TextFormatFlags.Bottom | TextFormatFlags.EndEllipsis; TextRenderer.DrawText(e.Graphics, "This is some text that will be clipped at the end.", this.Font, new Rectangle(10, 10, 100, 50), SystemColors.ControlText, flags); }
DrawText(IDeviceContext, String, Font, Point, Color, Color, TextFormatFlags)
使用指定的設備上下文、字體、顏色、背景色和格式說明在指定位置繪制指定文本。
public static void DrawText (System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Point pt, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Windows.Forms.TextFormatFlags flags);
參數
- dc IDeviceContext 繪制文本所使用的設備上下文。
- text String 要繪制的文本。
- flags TextFormatFlags TextFormatFlags 值的按位組合。
異常
dc
為 null
。
示例
下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText7
,並將 e
作為 @no__t。
private void RenderText7(PaintEventArgs e)
{ TextRenderer.DrawText(e.Graphics, "This is some text.", this.Font, new Point(10, 10), Color.White, Color.SteelBlue, TextFormatFlags.Default); }
DrawText(IDeviceContext, String, Font, Rectangle, Color, Color, TextFormatFlags)
使用指定的設備上下文、字體、顏色、背景色和格式說明在指定界限中繪制指定文本。
public static void DrawText (System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Windows.Forms.TextFormatFlags flags);
參數
- dc IDeviceContext 繪制文本所使用的設備上下文。
- text String 要繪制的文本。
- flags TextFormatFlags TextFormatFlags 值的按位組合。
異常
dc
為 null
。
示例
下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText8
,並將 e
作為 @no__t。
private void RenderText8(PaintEventArgs e)
{ TextFormatFlags flags = TextFormatFlags.Bottom | TextFormatFlags.WordBreak; TextRenderer.DrawText(e.Graphics, "This is some text that will display on multiple lines.", this.Font, new Rectangle(10, 10, 100, 50), SystemColors.ControlText, SystemColors.ControlDark, flags); }