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)

指定したデバイス コンテキスト、フォント、色、背景色、および書式設定の指示を使用して、指定した境界内に指定されたテキストを描画します。

注釈

TextRenderer クラスによって提供されるテキスト レンダリングは GDI テキスト レンダリングに基づいており、Windows フォームからの印刷ではサポートされていません。 代わりに、DrawString クラスのGraphics メソッドを使用します。

DrawText(IDeviceContext, String, Font, Point, Color)

指定したデバイス コンテキスト、フォント、色を使用して、指定したテキストを指定した場所に描画します。

public:
 static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Point pt, System::Drawing::Color foreColor);
public static void DrawText(System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Point pt, System.Drawing.Color foreColor);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Point * System.Drawing.Color -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, pt As Point, foreColor As Color)

パラメーター

dc
IDeviceContext

テキストを描画するデバイス コンテキスト。

text
String

描画するテキスト。

font
Font

描画されたテキストに適用する Font

pt
Point

描画されたテキストの左上隅を表す Point

foreColor
Color

描画されたテキストに適用する Color

例外

dcnullです。

次のコード例は、 DrawText メソッドの使用方法を示しています。 この例を実行するには、コードを Windows フォームに貼り付け、フォームの Paint イベント ハンドラーから RenderText1 を呼び出し、ePaintEventArgs として渡します。

private void RenderText1(PaintEventArgs e)
{
    TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font, 
        new Point(10, 10), SystemColors.ControlText);
}
Private Sub RenderText1(ByVal e As PaintEventArgs)
    TextRenderer.DrawText(e.Graphics, "Regular Text", _
        Me.Font, New Point(10, 10), SystemColors.ControlText)

End Sub

注釈

TextFormatFlags パラメーターを受け取るDrawTextオーバーロードのいずれかを使用して、テキストの描画方法を操作できます。

fontnullまたはforecolorColor.Emptyされている場合、DrawText メソッドは、dcで指定されたデバイス コンテキストで現在選択されているフォントまたは色でテキストを描画します。 forecolorTransparentされている場合、テキストは描画されません。

TextRenderer クラスによって提供されるテキスト レンダリングは GDI テキスト レンダリングに基づいており、Windows フォームからの印刷ではサポートされていません。 代わりに、DrawString クラスのGraphics メソッドを使用します。

Note

描画されたテキストの左上隅が Windows 2000 で正しくレンダリングされないため、Point を指定する DrawText メソッド。 アプリケーションが 2000 Windows実行されているコンピューターで使用することを目的としている場合は、描画されたテキストの境界に対して Rectangle を指定する DrawText メソッドのいずれかを使用する必要があります。

こちらもご覧ください

適用対象

DrawText(IDeviceContext, String, Font, Rectangle, Color)

指定したデバイス コンテキスト、フォント、色を使用して、指定した境界内に指定したテキストを描画します。

public:
 static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Rectangle bounds, System::Drawing::Color foreColor);
public static void DrawText(System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Rectangle * System.Drawing.Color -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, bounds As Rectangle, foreColor As Color)

パラメーター

dc
IDeviceContext

テキストを描画するデバイス コンテキスト。

text
String

描画するテキスト。

font
Font

描画されたテキストに適用する Font

bounds
Rectangle

テキストの境界を表す Rectangle

foreColor
Color

描画されたテキストに適用する Color

例外

dcnullです。

次のコード例は、 DrawText メソッドの使用方法を示しています。 この例を実行するには、コードを Windows フォームに貼り付け、フォームの Paint イベント ハンドラーから RenderText2 を呼び出し、ePaintEventArgs として渡します。

private void RenderText2(PaintEventArgs e)
{
    TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font,
        new Rectangle(10, 10, 100, 100), SystemColors.ControlText);
}
Private Sub RenderText2(ByVal e As PaintEventArgs)
    TextRenderer.DrawText(e.Graphics, "Regular Text", _
        Me.Font, New Rectangle(10, 10, 100, 100), _
        SystemColors.ControlText)

End Sub

注釈

fontまたはforecolorがそれぞれnullまたはColor.Emptyされている場合、DrawTextメソッドは、dcで指定されたデバイス コンテキストで現在選択されているフォントまたは色でテキストを描画します。 forecolorTransparentされている場合、テキストは描画されません。

このメソッドは、 bounds パラメーターで指定された四角形の水平方向と垂直方向の中央にテキストが生成されます。 テキストの描画方法を変更するには、TextFormatFlagsパラメーター型を受け取るDrawTextのバージョンを使用します。

TextRenderer クラスによって提供されるテキスト レンダリングは GDI テキスト レンダリングに基づいており、Windows フォームからの印刷ではサポートされていません。 代わりに、DrawString クラスのGraphics メソッドを使用します。

こちらもご覧ください

適用対象

DrawText(IDeviceContext, String, Font, Point, Color, Color)

指定したデバイス コンテキスト、フォント、色、および背景色を使用して、指定した位置に指定したテキストを描画します。

public:
 static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Point pt, System::Drawing::Color foreColor, System::Drawing::Color backColor);
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);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Point * System.Drawing.Color * System.Drawing.Color -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, pt As Point, foreColor As Color, backColor As Color)

パラメーター

dc
IDeviceContext

テキストを描画するデバイス コンテキスト。

text
String

描画するテキスト。

font
Font

描画されたテキストに適用する Font

pt
Point

描画されたテキストの左上隅を表す Point

foreColor
Color

描画されたテキストに適用する Color

backColor
Color

描画されたテキストの背景領域に適用する Color

例外

dcnullです。

次のコード例は、 DrawText メソッドの使用方法を示しています。 この例を実行するには、コードを Windows フォームに貼り付け、フォームの Paint イベント ハンドラーから RenderText3 を呼び出し、ePaintEventArgs として渡します。

private void RenderText3(PaintEventArgs e)
{
    TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font,
        new Point(10, 10), Color.Red, Color.PowderBlue);
}
Private Sub RenderText3(ByVal e As PaintEventArgs)
    TextRenderer.DrawText(e.Graphics, "Regular Text", Me.Font, _
        New Point(10, 10), Color.Red, Color.PowderBlue)

End Sub

注釈

backColor パラメーターは、描画されたテキストを含む四角形領域に適用されます。 fontbackcolor、またはforecolorがそれぞれnullまたはColor.Emptyされている場合、DrawText メソッドは、dcで指定されたデバイス コンテキストで現在選択されているフォントまたは色でテキストを描画します。 forecolorTransparentされている場合、テキストは描画されません。

TextFormatFlags パラメーターを受け取るDrawTextオーバーロードのいずれかを使用して、テキストの描画方法を操作できます。

TextRenderer クラスによって提供されるテキスト レンダリングは GDI テキスト レンダリングに基づいており、Windows フォームからの印刷ではサポートされていません。 代わりに、DrawString クラスのGraphics メソッドを使用します。

Note

描画されたテキストの左上隅が Windows 2000 で正しくレンダリングされないため、Point を指定する DrawText メソッド。 アプリケーションが 2000 Windows実行されているコンピューターで使用することを目的としている場合は、描画されたテキストの境界に対して Rectangle を指定する DrawText メソッドのいずれかを使用する必要があります。

適用対象

DrawText(IDeviceContext, String, Font, Point, Color, TextFormatFlags)

指定したデバイス コンテキスト、フォント、色、および書式設定の指示を使用して、指定したテキストを指定した場所に描画します。

public:
 static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Point pt, System::Drawing::Color foreColor, System::Windows::Forms::TextFormatFlags flags);
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);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Point * System.Drawing.Color * System.Windows.Forms.TextFormatFlags -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, pt As Point, foreColor As Color, flags As TextFormatFlags)

パラメーター

dc
IDeviceContext

テキストを描画するデバイス コンテキスト。

text
String

描画するテキスト。

font
Font

描画されたテキストに適用する Font

pt
Point

描画されたテキストの左上隅を表す Point

foreColor
Color

描画されたテキストに適用する Color

flags
TextFormatFlags

TextFormatFlags値のビットごとの組み合わせ。

例外

dcnullです。

次のコード例は、 DrawText メソッドの使用方法を示しています。 この例を実行するには、コードを Windows フォームに貼り付け、フォームの Paint イベント ハンドラーから RenderText5 を呼び出し、ePaintEventArgs として渡します。

private void RenderText5(PaintEventArgs e)
{
    TextRenderer.DrawText(e.Graphics, "Some text.",
        this.Font, new Point(10, 10), SystemColors.ControlText, TextFormatFlags.Bottom);
}
Private Sub RenderText5(ByVal e As PaintEventArgs)
    TextRenderer.DrawText(e.Graphics, "Some text.", _
    Me.Font, New Point(10, 10), SystemColors.ControlText, _
    TextFormatFlags.Bottom)

End Sub

注釈

TextFormatFlags パラメーターを受け取るDrawTextオーバーロードのいずれかを使用して、テキストの描画方法を操作できます。 たとえば、 TextRenderer の既定の動作では、描画されたテキストの外接する四角形にパディングを追加して、オーバーハングするグリフに対応します。 これらの余分なスペースなしでテキストの行を描画する必要がある場合は、SizeTextFormatFlagsパラメーターを受け取るDrawTextMeasureTextのバージョンを使用する必要があります。 例については、MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags)を参照してください。

backColor パラメーターは、bounds パラメーター内の領域に適用されます。 fontまたはforecolorがそれぞれnullまたはColor.Emptyされている場合、DrawTextメソッドは、dcで指定されたデバイス コンテキストで現在選択されているフォントまたは色でテキストを描画します。 forecolorTransparentされている場合、テキストは描画されません。

TextRenderer クラスによって提供されるテキスト レンダリングは GDI テキスト レンダリングに基づいており、Windows フォームからの印刷ではサポートされていません。 代わりに、DrawString クラスのGraphics メソッドを使用します。

TextRendererでは、描画されたテキストにタブ位置を追加することはできませんが、ExpandTabs フラグを使用して既存のタブ位置を展開することはできます。

Note

描画されたテキストの左上隅が Windows 2000 で正しくレンダリングされないため、Point を指定する DrawText メソッド。 アプリケーションが 2000 Windows実行されているコンピューターで使用することを目的としている場合は、描画されたテキストの境界に対して Rectangle を指定する DrawText メソッドのいずれかを使用する必要があります。

適用対象

DrawText(IDeviceContext, String, Font, Rectangle, Color, Color)

指定したデバイス コンテキスト、フォント、色、および背景色を使用して、指定した境界内に指定したテキストを描画します。

public:
 static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Rectangle bounds, System::Drawing::Color foreColor, System::Drawing::Color backColor);
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);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Rectangle * System.Drawing.Color * System.Drawing.Color -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, bounds As Rectangle, foreColor As Color, backColor As Color)

パラメーター

dc
IDeviceContext

テキストを描画するデバイス コンテキスト。

text
String

描画するテキスト。

font
Font

描画されたテキストに適用する Font

bounds
Rectangle

テキストの境界を表す Rectangle

foreColor
Color

描画されたテキストに適用する Color

backColor
Color

boundsで表される領域に適用するColor

例外

dcnullです。

次のコード例は、 DrawText メソッドの使用方法を示しています。 この例を実行するには、コードを Windows フォームに貼り付け、フォームの Paint イベント ハンドラーから RenderText4 を呼び出し、ePaintEventArgs として渡します。

private void RenderText4(PaintEventArgs e)
{
    TextRenderer.DrawText(e.Graphics, "Regular Text.", this.Font,
        new Rectangle(10, 10, 70, 70), SystemColors.ControlText, 
        SystemColors.ControlDark);
}
Private Sub RenderText4(ByVal e As PaintEventArgs)
    TextRenderer.DrawText(e.Graphics, "Regular Text.", _
        Me.Font, New Rectangle(10, 10, 70, 70), _
        SystemColors.ControlText, SystemColors.ControlDark)

End Sub

注釈

backColor パラメーターは、bounds パラメーター内の領域に適用されます。 fontbackcolor、またはforecolorがそれぞれnullまたはEmptyされている場合、DrawText メソッドは、dcで指定されたデバイス コンテキストで現在選択されているフォントまたは色でテキストを描画します。 forecolorTransparentされている場合、テキストは描画されません。

このメソッドは、 bounds パラメーターで指定された四角形の水平方向と垂直方向の中央にテキストが生成されます。 テキストの描画方法を変更するには、TextFormatFlagsパラメーター型を受け取るDrawTextのバージョンを使用します。

TextRenderer クラスによって提供されるテキスト レンダリングは GDI テキスト レンダリングに基づいており、Windows フォームからの印刷ではサポートされていません。 代わりに、DrawString クラスのGraphics メソッドを使用します。

適用対象

DrawText(IDeviceContext, String, Font, Rectangle, Color, TextFormatFlags)

指定したデバイス コンテキスト、フォント、色、および書式設定の指示を使用して、指定した境界内に指定したテキストを描画します。

public:
 static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Rectangle bounds, System::Drawing::Color foreColor, System::Windows::Forms::TextFormatFlags flags);
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);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Rectangle * System.Drawing.Color * System.Windows.Forms.TextFormatFlags -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, bounds As Rectangle, foreColor As Color, flags As TextFormatFlags)

パラメーター

dc
IDeviceContext

テキストを描画するデバイス コンテキスト。

text
String

描画するテキスト。

font
Font

描画されたテキストに適用する Font

bounds
Rectangle

テキストの境界を表す Rectangle

foreColor
Color

描画されたテキストに適用する Color

flags
TextFormatFlags

TextFormatFlags値のビットごとの組み合わせ。

例外

dcnullです。

次のコード例は、 DrawText メソッドの使用方法を示しています。 この例を実行するには、コードを Windows フォームに貼り付け、フォームの Paint イベント ハンドラーから RenderText6 を呼び出し、ePaintEventArgs として渡します。

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);
}
Private Sub RenderText6(ByVal e As PaintEventArgs)
    Dim flags As TextFormatFlags = TextFormatFlags.Bottom Or _
        TextFormatFlags.EndEllipsis
    TextRenderer.DrawText(e.Graphics, _
    "This is some text that will be clipped at the end.", _
    Me.Font, New Rectangle(10, 10, 100, 50), SystemColors.ControlText, flags)

End Sub

注釈

fontまたはcolorがそれぞれnullまたはEmptyされている場合、DrawTextメソッドは、dcで指定されたデバイス コンテキストで現在選択されているフォントまたは色でテキストを描画します。 forecolorTransparentされている場合、テキストは描画されません。

TextFormatFlags パラメーターを受け取るDrawTextオーバーロードのいずれかを使用して、テキストの描画方法を操作できます。 たとえば、 TextRenderer の既定の動作では、描画されたテキストの外接する四角形にパディングを追加して、オーバーハングするグリフに対応します。 これらの余分なスペースなしでテキストの行を描画する必要がある場合は、SizeTextFormatFlagsパラメーターを受け取るDrawTextMeasureTextのバージョンを使用する必要があります。 例については、MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags)を参照してください。

TextRenderer クラスによって提供されるテキスト レンダリングは GDI テキスト レンダリングに基づいており、Windows フォームからの印刷ではサポートされていません。 代わりに、DrawString クラスのGraphics メソッドを使用します。

TextRendererでは、描画されたテキストにタブ位置を追加することはできませんが、ExpandTabs フラグを使用して既存のタブ位置を展開することはできます。

適用対象

DrawText(IDeviceContext, String, Font, Point, Color, Color, TextFormatFlags)

指定したデバイス コンテキスト、フォント、色、背景色、および書式設定の指示を使用して、指定したテキストを指定した場所に描画します。

public:
 static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Point pt, System::Drawing::Color foreColor, System::Drawing::Color backColor, System::Windows::Forms::TextFormatFlags flags);
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);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Point * System.Drawing.Color * System.Drawing.Color * System.Windows.Forms.TextFormatFlags -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, pt As Point, foreColor As Color, backColor As Color, flags As TextFormatFlags)

パラメーター

dc
IDeviceContext

テキストを描画するデバイス コンテキスト。

text
String

描画するテキスト。

font
Font

描画されたテキストに適用する Font

pt
Point

描画されたテキストの左上隅を表す Point

foreColor
Color

テキストに適用する Color

backColor
Color

描画されたテキストの背景領域に適用する Color

flags
TextFormatFlags

TextFormatFlags値のビットごとの組み合わせ。

例外

dcnullです。

次のコード例は、 DrawText メソッドの使用方法を示しています。 この例を実行するには、コードを Windows フォームに貼り付け、フォームの Paint イベント ハンドラーから RenderText7 を呼び出し、ePaintEventArgs として渡します。

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);
}
Private Sub RenderText7(ByVal e As PaintEventArgs)
    TextRenderer.DrawText(e.Graphics, "This is some text.", _
        Me.Font, New Point(10, 10), Color.White, Color.SteelBlue, _
        TextFormatFlags.Default)

End Sub

注釈

backcolorパラメーターは、描画されたテキストを含む四角形領域に適用されます。 fontまたはforecolorがそれぞれnullまたはEmptyされている場合、DrawTextメソッドは、dcで指定されたデバイス コンテキストで現在選択されているフォントまたは色でテキストを描画します。 forecolorTransparentされている場合、テキストは描画されません。

TextFormatFlags パラメーターを受け取るDrawTextオーバーロードのいずれかを使用して、テキストの描画方法を操作できます。 たとえば、 TextRenderer の既定の動作では、描画されたテキストの外接する四角形にパディングを追加して、オーバーハングするグリフに対応します。 これらの余分なスペースなしでテキストの行を描画する必要がある場合は、SizeTextFormatFlagsパラメーターを受け取るDrawTextMeasureTextのバージョンを使用する必要があります。 例については、MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags)を参照してください。

TextRenderer クラスによって提供されるテキスト レンダリングは GDI テキスト レンダリングに基づいており、Windows フォームからの印刷ではサポートされていません。 代わりに、DrawString クラスのGraphics メソッドを使用します。

TextRendererでは、描画されたテキストにタブ位置を追加することはできませんが、ExpandTabs フラグを使用して既存のタブ位置を展開することはできます。

Note

描画されたテキストの左上隅が Windows 2000 で正しくレンダリングされないため、Point を指定する DrawText メソッド。 アプリケーションが 2000 Windows実行されているコンピューターで使用することを目的としている場合は、描画されたテキストの境界に対して Rectangle を指定する DrawText メソッドのいずれかを使用する必要があります。

適用対象

DrawText(IDeviceContext, String, Font, Rectangle, Color, Color, TextFormatFlags)

指定したデバイス コンテキスト、フォント、色、背景色、および書式設定の指示を使用して、指定した境界内に指定されたテキストを描画します。

public:
 static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Rectangle bounds, System::Drawing::Color foreColor, System::Drawing::Color backColor, System::Windows::Forms::TextFormatFlags flags);
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);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Rectangle * System.Drawing.Color * System.Drawing.Color * System.Windows.Forms.TextFormatFlags -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, bounds As Rectangle, foreColor As Color, backColor As Color, flags As TextFormatFlags)

パラメーター

dc
IDeviceContext

テキストを描画するデバイス コンテキスト。

text
String

描画するテキスト。

font
Font

描画されたテキストに適用する Font

bounds
Rectangle

テキストの境界を表す Rectangle

foreColor
Color

テキストに適用する Color

backColor
Color

boundsで表される領域に適用するColor

flags
TextFormatFlags

TextFormatFlags値のビットごとの組み合わせ。

例外

dcnullです。

次のコード例は、 DrawText メソッドの使用方法を示しています。 この例を実行するには、コードを Windows フォームに貼り付け、フォームの Paint イベント ハンドラーから RenderText8 を呼び出し、ePaintEventArgs として渡します。

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);
}
Private Sub RenderText8(ByVal e As PaintEventArgs)
    Dim flags As TextFormatFlags = _
        TextFormatFlags.Bottom Or TextFormatFlags.WordBreak
    TextRenderer.DrawText(e.Graphics, _
        "This is some text that will display on multiple lines.", _
        Me.Font, New Rectangle(10, 10, 100, 50), _
        SystemColors.ControlText, SystemColors.ControlDark, flags)

End Sub

注釈

backcolor パラメーターは、bounds パラメーター内の領域に適用されます.fontforecolor、またはbackcolorがそれぞれnullまたはEmptyDrawText メソッドは、dcで指定されたデバイス コンテキストで現在選択されているフォントまたは色でテキストを描画します。 forecolorTransparentされている場合、テキストは描画されません。

TextFormatFlags パラメーターを受け取るDrawTextオーバーロードのいずれかを使用して、テキストの描画方法を操作できます。 たとえば、 TextRenderer の既定の動作では、描画されたテキストの外接する四角形にパディングを追加して、オーバーハングするグリフに対応します。 これらの余分なスペースなしでテキストの行を描画する必要がある場合は、SizeTextFormatFlagsパラメーターを受け取るDrawTextMeasureTextのバージョンを使用する必要があります。 例については、MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags)を参照してください。

TextRenderer クラスによって提供されるテキスト レンダリングは GDI テキスト レンダリングに基づいており、Windows フォームからの印刷ではサポートされていません。 代わりに、DrawString クラスのGraphics メソッドを使用します。

TextRendererでは、描画されたテキストにタブ位置を追加することはできませんが、ExpandTabs フラグを使用して既存のタブ位置を展開することはできます。

適用対象