TextRenderer.DrawText 方法


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)

使用指定的設備上下文、字體和顏色在指定位置繪制指定文本。

C#   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   要繪制的文本。
font  Font   要應用於所繪制文本的 Font
pt  Point   表示所繪制文本左上角的 Point
foreColor  Color   要應用於所繪制文本的 Color

示例

下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText1,並將 e 作為 @no__t。

C#
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)

使用指定的設備上下文、字體和顏色在指定界限中繪制指定文本。

C#  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   要繪制的文本。
font  Font  要應用於所繪制文本的 Font
bounds  Rectangle  表示文本界限的 Rectangle
foreColor  Color   要應用於所繪制文本的 Color

異常

ArgumentNullException dc 為 null

示例

下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText2,並將 e 作為 @no__t。

C# 
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)

使用指定的設備上下文、字體、顏色和背景色在指定位置繪制指定文本。

C#
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  要繪制的文本。
font  Font  要應用於所繪制文本的 Font
pt  Point  表示所繪制文本左上角的 Point
foreColor  Color  要應用於所繪制文本的 Color
backColor  Color  要應用於所繪制文本的背景區域的 Color

異常

ArgumentNullException 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)

使用指定的設備上下文、字體、顏色和格式說明在指定位置繪制指定文本。

C#
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 要繪制的文本。
font Font 要應用於所繪制文本的 Font
pt Point 表示所繪制文本左上角的 Point
foreColor Color 要應用於所繪制文本的 Color
flags TextFormatFlags  TextFormatFlags 值的按位組合。

異常

ArgumentNullException dc 為 null

示例

下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText5,並將 e 作為 @no__t。

C#
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)

使用指定的設備上下文、字體、顏色和背景色在指定界限中繪制指定文本。

C#
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 要繪制的文本。
font Font 要應用於所繪制文本的 Font
bounds Rectangle 表示文本界限的 Rectangle
foreColor Color 要應用於所繪制文本的 Color
backColor Color 要應用於 bounds 所表示區域的 Color

異常

ArgumentNullException dc 為 null

示例

下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText4,並將 e 作為 @no__t。

C#
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)

使用指定的設備上下文、字體、顏色和格式說明在指定界限中繪制指定文本。

C#
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 要繪制的文本。
font Font 要應用於所繪制文本的 Font
bounds Rectangle 表示文本界限的 Rectangle
foreColor Color 要應用於所繪制文本的 Color
flags TextFormatFlags   TextFormatFlags 值的按位組合。

異常

ArgumentNullException dc 為 null

示例

下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText6,並將 e 作為 @no__t。

C#
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)

使用指定的設備上下文、字體、顏色、背景色和格式說明在指定位置繪制指定文本。

C#
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 要繪制的文本。
font Font 要應用於所繪制文本的 Font
pt Point 表示所繪制文本左上角的 Point
foreColor Color 要應用於文本的 Color
backColor Color 要應用於所繪制文本的背景區域的 Color
flags TextFormatFlags   TextFormatFlags 值的按位組合。

異常

ArgumentNullException dc 為 null

示例

下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText7,並將 e 作為 @no__t。

C#
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)

使用指定的設備上下文、字體、顏色、背景色和格式說明在指定界限中繪制指定文本。

C#
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  要繪制的文本。
font Font  要應用於所繪制文本的 Font
bounds Rectangle   表示文本界限的 Rectangle
foreColor Color   要應用於文本的 Color
backColor  Color    要應用於 bounds 所表示區域的 Color
flags  TextFormatFlags    TextFormatFlags 值的按位組合。

異常

dc 為 null

示例

下面的代碼示例演示如何使用 DrawText 方法。 若要運行此示例,請將代碼粘貼到 Windows 窗體中,並從窗體的 @no__t 事件處理程序中調用 RenderText8,並將 e 作為 @no__t。

C#
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); } 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM