Graphics.DrawString メソッド

定義

指定した Brush オブジェクトと Font オブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

オーバーロード

名前 説明
DrawString(String, Font, Brush, Single, Single, StringFormat)

指定したBrushの書式設定属性を使用して、指定したFontStringFormatオブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

DrawString(ReadOnlySpan<Char>, Font, Brush, Single, Single, StringFormat)

指定したBrushの書式設定属性を使用して、指定したFontStringFormatオブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

DrawString(String, Font, Brush, Single, Single)

指定した Brush オブジェクトと Font オブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

DrawString(String, Font, Brush, RectangleF, StringFormat)

指定したBrushの書式設定属性を使用して、指定したFontStringFormatオブジェクトを使用して、指定した四角形に指定したテキスト文字列を描画します。

DrawString(String, Font, Brush, PointF, StringFormat)

指定したBrushの書式設定属性を使用して、指定したFontStringFormatオブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

DrawString(ReadOnlySpan<Char>, Font, Brush, Single, Single)

指定した Brush オブジェクトと Font オブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

DrawString(ReadOnlySpan<Char>, Font, Brush, PointF, StringFormat)

指定したBrushの書式設定属性を使用して、指定したFontStringFormatオブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

DrawString(String, Font, Brush, RectangleF)

指定した Brush オブジェクトと Font オブジェクトを使用して、指定した四角形に指定したテキスト文字列を描画します。

DrawString(String, Font, Brush, PointF)

指定した Brush オブジェクトと Font オブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

DrawString(ReadOnlySpan<Char>, Font, Brush, RectangleF)

指定した Brush オブジェクトと Font オブジェクトを使用して、指定した四角形に指定したテキスト文字列を描画します。

DrawString(ReadOnlySpan<Char>, Font, Brush, PointF)

指定した Brush オブジェクトと Font オブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

DrawString(ReadOnlySpan<Char>, Font, Brush, RectangleF, StringFormat)

指定したBrushの書式設定属性を使用して、指定したFontStringFormatオブジェクトを使用して、指定した四角形に指定したテキスト文字列を描画します。

DrawString(String, Font, Brush, Single, Single, StringFormat)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定したBrushの書式設定属性を使用して、指定したFontStringFormatオブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

public:
 void DrawString(System::String ^ s, System::Drawing::Font ^ font, System::Drawing::Brush ^ brush, float x, float y, System::Drawing::StringFormat ^ format);
public void DrawString(string? s, System.Drawing.Font font, System.Drawing.Brush brush, float x, float y, System.Drawing.StringFormat? format);
public void DrawString(string s, System.Drawing.Font font, System.Drawing.Brush brush, float x, float y, System.Drawing.StringFormat format);
member this.DrawString : string * System.Drawing.Font * System.Drawing.Brush * single * single * System.Drawing.StringFormat -> unit
Public Sub DrawString (s As String, font As Font, brush As Brush, x As Single, y As Single, format As StringFormat)

パラメーター

s
String

描画する文字列。

font
Font

Font 文字列のテキスト形式を定義する

brush
Brush

Brush 描画されたテキストの色とテクスチャを決定する

x
Single

描画されたテキストの左上隅の x 座標。

y
Single

描画されたテキストの左上隅の y 座標。

format
StringFormat

StringFormat 描画されたテキストに適用される書式属性 (行間や配置など) を指定します。

例外

brushnullです。

-又は-

snullです。

次のコード例は、Windows Formsで使用するように設計されており、PaintEventArgse が必要です。これは、Paint イベント ハンドラーのパラメーターです。 このコードは、次のアクションを実行します。

  • 描画するテキスト文字列を作成します。

  • フォントを Arial (16pt) として定義します。

  • 描画するソリッドの黒いブラシを作成します。

  • テキストを描画する左上隅のポイントの座標を作成します。

  • 垂直方向に描画する文字列の形式を設定します。

  • フォント、ブラシ、変換先、書式を使用して、文字列を画面に描画します。

public:
   void DrawStringFloatFormat( PaintEventArgs^ e )
   {
      // Create string to draw.
      String^ drawString = "Sample Text";

      // Create font and brush.
      System::Drawing::Font^ drawFont = gcnew System::Drawing::Font( "Arial",16 );
      SolidBrush^ drawBrush = gcnew SolidBrush( Color::Black );

      // Create point for upper-left corner of drawing.
      float x = 150.0F;
      float y = 50.0F;

      // Set format of string.
      StringFormat^ drawFormat = gcnew StringFormat;
      drawFormat->FormatFlags = StringFormatFlags::DirectionVertical;

      // Draw string to screen.
      e->Graphics->DrawString( drawString, drawFont, drawBrush, x, y, drawFormat );
   }
public void DrawStringFloatFormat(PaintEventArgs e)
{
             
    // Create string to draw.
    String drawString = "Sample Text";
             
    // Create font and brush.
    Font drawFont = new Font("Arial", 16);
    SolidBrush drawBrush = new SolidBrush(Color.Black);
             
    // Create point for upper-left corner of drawing.
    float x = 150.0F;
    float y =  50.0F;
             
    // Set format of string.
    StringFormat drawFormat = new StringFormat();
    drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
             
    // Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
}
Public Sub DrawStringFloatFormat(ByVal e As PaintEventArgs)

    ' Create string to draw.
    Dim drawString As [String] = "Sample Text"

    ' Create font and brush.
    Dim drawFont As New Font("Arial", 16)
    Dim drawBrush As New SolidBrush(Color.Black)

    ' Create point for upper-left corner of drawing.
    Dim x As Single = 150.0F
    Dim y As Single = 50.0F

    ' Set format of string.
    Dim drawFormat As New StringFormat
    drawFormat.FormatFlags = StringFormatFlags.DirectionVertical

    ' Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, _
    x, y, drawFormat)
End Sub

こちらもご覧ください

適用対象

DrawString(ReadOnlySpan<Char>, Font, Brush, Single, Single, StringFormat)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定したBrushの書式設定属性を使用して、指定したFontStringFormatオブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

public:
 void DrawString(ReadOnlySpan<char> s, System::Drawing::Font ^ font, System::Drawing::Brush ^ brush, float x, float y, System::Drawing::StringFormat ^ format);
public void DrawString(ReadOnlySpan<char> s, System.Drawing.Font font, System.Drawing.Brush brush, float x, float y, System.Drawing.StringFormat? format);
member this.DrawString : ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Brush * single * single * System.Drawing.StringFormat -> unit
Public Sub DrawString (s As ReadOnlySpan(Of Char), font As Font, brush As Brush, x As Single, y As Single, format As StringFormat)

パラメーター

s
ReadOnlySpan<Char>

描画する文字列。

font
Font

Font 文字列のテキスト形式を定義する

brush
Brush

Brush 描画されたテキストの色とテクスチャを決定する

x
Single

描画されたテキストの左上隅の x 座標。

y
Single

描画されたテキストの左上隅の y 座標。

format
StringFormat

StringFormat 描画されたテキストに適用される書式属性 (行間や配置など) を指定します。

適用対象

DrawString(String, Font, Brush, Single, Single)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定した Brush オブジェクトと Font オブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

public:
 void DrawString(System::String ^ s, System::Drawing::Font ^ font, System::Drawing::Brush ^ brush, float x, float y);
public void DrawString(string? s, System.Drawing.Font font, System.Drawing.Brush brush, float x, float y);
public void DrawString(string s, System.Drawing.Font font, System.Drawing.Brush brush, float x, float y);
member this.DrawString : string * System.Drawing.Font * System.Drawing.Brush * single * single -> unit
Public Sub DrawString (s As String, font As Font, brush As Brush, x As Single, y As Single)

パラメーター

s
String

描画する文字列。

font
Font

Font 文字列のテキスト形式を定義する

brush
Brush

Brush 描画されたテキストの色とテクスチャを決定する

x
Single

描画されたテキストの左上隅の x 座標。

y
Single

描画されたテキストの左上隅の y 座標。

例外

brushnullです。

-又は-

snullです。

次のコード例は、Windows Formsで使用するように設計されており、PaintEventArgse が必要です。これは、Paint イベント ハンドラーのパラメーターです。 このコードは、次のアクションを実行します。

  • 描画するテキスト文字列を作成します。

  • フォントを Arial (16pt) として定義します。

  • 描画に使用する黒いソリッド ブラシを作成します。

  • テキストを描画する左上隅のポイントを作成します。

  • フォント、ブラシ、および変換先のポイントを使用して、文字列を画面に描画します。

public:
   void DrawStringFloat( PaintEventArgs^ e )
   {
      // Create string to draw.
      String^ drawString = "Sample Text";

      // Create font and brush.
      System::Drawing::Font^ drawFont = gcnew System::Drawing::Font( "Arial",16 );
      SolidBrush^ drawBrush = gcnew SolidBrush( Color::Black );

      // Create point for upper-left corner of drawing.
      float x = 150.0F;
      float y = 150.0F;

      // Draw string to screen.
      e->Graphics->DrawString( drawString, drawFont, drawBrush, x, y );
   }
public void DrawStringFloat(PaintEventArgs e)
{
             
    // Create string to draw.
    String drawString = "Sample Text";
             
    // Create font and brush.
    Font drawFont = new Font("Arial", 16);
    SolidBrush drawBrush = new SolidBrush(Color.Black);
             
    // Create point for upper-left corner of drawing.
    float x = 150.0F;
    float y = 150.0F;
             
    // Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y);
}
Public Sub DrawStringFloat(ByVal e As PaintEventArgs)

    ' Create string to draw.
    Dim drawString As [String] = "Sample Text"

    ' Create font and brush.
    Dim drawFont As New Font("Arial", 16)
    Dim drawBrush As New SolidBrush(Color.Black)

    ' Create point for upper-left corner of drawing.
    Dim x As Single = 150.0F
    Dim y As Single = 150.0F

    ' Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y)
End Sub

こちらもご覧ください

適用対象

DrawString(String, Font, Brush, RectangleF, StringFormat)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定したBrushの書式設定属性を使用して、指定したFontStringFormatオブジェクトを使用して、指定した四角形に指定したテキスト文字列を描画します。

public:
 void DrawString(System::String ^ s, System::Drawing::Font ^ font, System::Drawing::Brush ^ brush, System::Drawing::RectangleF layoutRectangle, System::Drawing::StringFormat ^ format);
public void DrawString(string? s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.RectangleF layoutRectangle, System.Drawing.StringFormat? format);
public void DrawString(string s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.RectangleF layoutRectangle, System.Drawing.StringFormat format);
member this.DrawString : string * System.Drawing.Font * System.Drawing.Brush * System.Drawing.RectangleF * System.Drawing.StringFormat -> unit
Public Sub DrawString (s As String, font As Font, brush As Brush, layoutRectangle As RectangleF, format As StringFormat)

パラメーター

s
String

描画する文字列。

font
Font

Font 文字列のテキスト形式を定義する

brush
Brush

Brush 描画されたテキストの色とテクスチャを決定する

layoutRectangle
RectangleF

RectangleF 描画されたテキストの位置を指定する構造体。

format
StringFormat

StringFormat 描画されたテキストに適用される書式属性 (行間や配置など) を指定します。

例外

brushnullです。

-又は-

snullです。

次のコード例は、Windows Formsで使用するように設計されており、PaintEventArgse が必要です。これは、Paint イベント ハンドラーのパラメーターです。 このコードは、次のアクションを実行します。

  • 描画するテキスト文字列を作成します。

  • フォントを Arial (16pt) として定義します。

  • 描画するソリッドの黒いブラシを作成します。

  • テキストを描画する四角形を作成します。

  • 四角形を画面に描画します。

  • 文字列の書式を四角形内の中央に設定します。

  • フォント、ブラシ、および変換先の四角形を使用して、文字列を画面に描画します。

public:
   void DrawStringRectangleFFormat( PaintEventArgs^ e )
   {
      // Create string to draw.
      String^ drawString = "Sample Text";

      // Create font and brush.
      System::Drawing::Font^ drawFont = gcnew System::Drawing::Font( "Arial",16 );
      SolidBrush^ drawBrush = gcnew SolidBrush( Color::Black );

      // Create rectangle for drawing.
      float x = 150.0F;
      float y = 150.0F;
      float width = 200.0F;
      float height = 50.0F;
      RectangleF drawRect = RectangleF(x,y,width,height);

      // Draw rectangle to screen.
      Pen^ blackPen = gcnew Pen( Color::Black );
      e->Graphics->DrawRectangle( blackPen, x, y, width, height );

      // Set format of string.
      StringFormat^ drawFormat = gcnew StringFormat;
      drawFormat->Alignment = StringAlignment::Center;

      // Draw string to screen.
      e->Graphics->DrawString( drawString, drawFont, drawBrush, drawRect, drawFormat );
   }
public void DrawStringRectangleFFormat(PaintEventArgs e)
{
             
    // Create string to draw.
    String drawString = "Sample Text";
             
    // Create font and brush.
    Font drawFont = new Font("Arial", 16);
    SolidBrush drawBrush = new SolidBrush(Color.Black);
             
    // Create rectangle for drawing.
    float x = 150.0F;
    float y = 150.0F;
    float width = 200.0F;
    float height = 50.0F;
    RectangleF drawRect = new RectangleF(x, y, width, height);
             
    // Draw rectangle to screen.
    Pen blackPen = new Pen(Color.Black);
    e.Graphics.DrawRectangle(blackPen, x, y, width, height);
             
    // Set format of string.
    StringFormat drawFormat = new StringFormat();
    drawFormat.Alignment = StringAlignment.Center;
             
    // Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, drawRect, drawFormat);
}
Public Sub DrawStringRectangleFFormat(ByVal e As PaintEventArgs)

    ' Create string to draw.
    Dim drawString As [String] = "Sample Text"

    ' Create font and brush.
    Dim drawFont As New Font("Arial", 16)
    Dim drawBrush As New SolidBrush(Color.Black)

    ' Create rectangle for drawing.
    Dim x As Single = 150.0F
    Dim y As Single = 150.0F
    Dim width As Single = 200.0F
    Dim height As Single = 50.0F
    Dim drawRect As New RectangleF(x, y, width, height)

    ' Draw rectangle to screen.
    Dim blackPen As New Pen(Color.Black)
    e.Graphics.DrawRectangle(blackPen, x, y, width, height)

    ' Set format of string.
    Dim drawFormat As New StringFormat
    drawFormat.Alignment = StringAlignment.Center

    ' Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, _
    drawRect, drawFormat)
End Sub

注釈

s パラメーターで表されるテキストは、layoutRectangle パラメーターで表される四角形内に描画されます。 テキストが四角形内に収まらない場合は、 format パラメーターで特に指定しない限り、最も近い単語で切り捨てられます。

こちらもご覧ください

適用対象

DrawString(String, Font, Brush, PointF, StringFormat)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定したBrushの書式設定属性を使用して、指定したFontStringFormatオブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

public:
 void DrawString(System::String ^ s, System::Drawing::Font ^ font, System::Drawing::Brush ^ brush, System::Drawing::PointF point, System::Drawing::StringFormat ^ format);
public void DrawString(string? s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.PointF point, System.Drawing.StringFormat? format);
public void DrawString(string s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.PointF point, System.Drawing.StringFormat format);
member this.DrawString : string * System.Drawing.Font * System.Drawing.Brush * System.Drawing.PointF * System.Drawing.StringFormat -> unit
Public Sub DrawString (s As String, font As Font, brush As Brush, point As PointF, format As StringFormat)

パラメーター

s
String

描画する文字列。

font
Font

Font 文字列のテキスト形式を定義する

brush
Brush

Brush 描画されたテキストの色とテクスチャを決定する

point
PointF

PointF 描画されたテキストの左上隅を指定する構造体。

format
StringFormat

StringFormat 描画されたテキストに適用される書式属性 (行間や配置など) を指定します。

例外

brushnullです。

-又は-

snullです。

次のコード例は、Windows Formsで使用するように設計されており、PaintEventArgse が必要です。これは、Paint イベント ハンドラーのパラメーターです。 このコードは、次のアクションを実行します。

  • 描画するテキスト文字列を作成します。

  • フォントを Arial (16pt) として定義します。

  • 描画するソリッドの黒いブラシを作成します。

  • テキストを描画する左上隅のポイントを作成します。

  • 垂直方向に描画する文字列の形式を設定します。

  • フォント、ブラシ、変換先、書式を使用して、文字列を画面に描画します。

public:
   void DrawStringPointFFormat( PaintEventArgs^ e )
   {
      // Create string to draw.
      String^ drawString = "Sample Text";

      // Create font and brush.
      System::Drawing::Font^ drawFont = gcnew System::Drawing::Font( "Arial",16 );
      SolidBrush^ drawBrush = gcnew SolidBrush( Color::Black );

      // Create point for upper-left corner of drawing.
      PointF drawPoint = PointF(150.0F,50.0F);

      // Set format of string.
      StringFormat^ drawFormat = gcnew StringFormat;
      drawFormat->FormatFlags = StringFormatFlags::DirectionVertical;

      // Draw string to screen.
      e->Graphics->DrawString( drawString, drawFont, drawBrush, drawPoint, drawFormat );
   }
public void DrawStringPointFFormat(PaintEventArgs e)
{
             
    // Create string to draw.
    String drawString = "Sample Text";
             
    // Create font and brush.
    Font drawFont = new Font("Arial", 16);
    SolidBrush drawBrush = new SolidBrush(Color.Black);
             
    // Create point for upper-left corner of drawing.
    PointF drawPoint = new PointF(150.0F, 50.0F);
             
    // Set format of string.
    StringFormat drawFormat = new StringFormat();
    drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
             
    // Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint, drawFormat);
}
Public Sub DrawStringPointFFormat(ByVal e As PaintEventArgs)

    ' Create string to draw.
    Dim drawString As [String] = "Sample Text"

    ' Create font and brush.
    Dim drawFont As New Font("Arial", 16)
    Dim drawBrush As New SolidBrush(Color.Black)

    ' Create point for upper-left corner of drawing.
    Dim drawPoint As New PointF(150.0F, 50.0F)

    ' Set format of string.
    Dim drawFormat As New StringFormat
    drawFormat.FormatFlags = StringFormatFlags.DirectionVertical

    ' Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, _
    drawPoint, drawFormat)
End Sub

こちらもご覧ください

適用対象

DrawString(ReadOnlySpan<Char>, Font, Brush, Single, Single)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定した Brush オブジェクトと Font オブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

public:
 void DrawString(ReadOnlySpan<char> s, System::Drawing::Font ^ font, System::Drawing::Brush ^ brush, float x, float y);
public void DrawString(ReadOnlySpan<char> s, System.Drawing.Font font, System.Drawing.Brush brush, float x, float y);
member this.DrawString : ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Brush * single * single -> unit
Public Sub DrawString (s As ReadOnlySpan(Of Char), font As Font, brush As Brush, x As Single, y As Single)

パラメーター

s
ReadOnlySpan<Char>

描画する文字列。

font
Font

Font 文字列のテキスト形式を定義する

brush
Brush

Brush 描画されたテキストの色とテクスチャを決定する

x
Single

描画されたテキストの左上隅の x 座標。

y
Single

描画されたテキストの左上隅の y 座標。

適用対象

DrawString(ReadOnlySpan<Char>, Font, Brush, PointF, StringFormat)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定したBrushの書式設定属性を使用して、指定したFontStringFormatオブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

public:
 void DrawString(ReadOnlySpan<char> s, System::Drawing::Font ^ font, System::Drawing::Brush ^ brush, System::Drawing::PointF point, System::Drawing::StringFormat ^ format);
public void DrawString(ReadOnlySpan<char> s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.PointF point, System.Drawing.StringFormat? format);
member this.DrawString : ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Brush * System.Drawing.PointF * System.Drawing.StringFormat -> unit
Public Sub DrawString (s As ReadOnlySpan(Of Char), font As Font, brush As Brush, point As PointF, format As StringFormat)

パラメーター

s
ReadOnlySpan<Char>

描画する文字列。

font
Font

Font 文字列のテキスト形式を定義する

brush
Brush

Brush 描画されたテキストの色とテクスチャを決定する

point
PointF

PointF 描画されたテキストの左上隅を指定する構造体。

format
StringFormat

StringFormat 描画されたテキストに適用される書式属性 (行間や配置など) を指定します。

適用対象

DrawString(String, Font, Brush, RectangleF)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定した Brush オブジェクトと Font オブジェクトを使用して、指定した四角形に指定したテキスト文字列を描画します。

public:
 void DrawString(System::String ^ s, System::Drawing::Font ^ font, System::Drawing::Brush ^ brush, System::Drawing::RectangleF layoutRectangle);
public void DrawString(string? s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.RectangleF layoutRectangle);
public void DrawString(string s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.RectangleF layoutRectangle);
member this.DrawString : string * System.Drawing.Font * System.Drawing.Brush * System.Drawing.RectangleF -> unit
Public Sub DrawString (s As String, font As Font, brush As Brush, layoutRectangle As RectangleF)

パラメーター

s
String

描画する文字列。

font
Font

Font 文字列のテキスト形式を定義する

brush
Brush

Brush 描画されたテキストの色とテクスチャを決定する

layoutRectangle
RectangleF

RectangleF 描画されたテキストの位置を指定する構造体。

例外

brushnullです。

-又は-

snullです。

次のコード例は、Windows Formsで使用するように設計されており、PaintEventArgse が必要です。これは、Paint イベント ハンドラーのパラメーターです。 このコードは、次のアクションを実行します。

  • 描画するテキスト文字列を作成します。

  • フォントを Arial (16pt) として定義します。

  • 描画するソリッドの黒いブラシを作成します。

  • テキストを描画する四角形を作成します。

  • 四角形を画面に描画します。

  • フォント、ブラシ、および変換先の四角形を使用して、文字列を画面に描画します。

public:
   void DrawStringRectangleF( PaintEventArgs^ e )
   {
      // Create string to draw.
      String^ drawString = "Sample Text";

      // Create font and brush.
      System::Drawing::Font^ drawFont = gcnew System::Drawing::Font( "Arial",16 );
      SolidBrush^ drawBrush = gcnew SolidBrush( Color::Black );

      // Create rectangle for drawing.
      float x = 150.0F;
      float y = 150.0F;
      float width = 200.0F;
      float height = 50.0F;
      RectangleF drawRect = RectangleF(x,y,width,height);

      // Draw rectangle to screen.
      Pen^ blackPen = gcnew Pen( Color::Black );
      e->Graphics->DrawRectangle( blackPen, x, y, width, height );

      // Draw string to screen.
      e->Graphics->DrawString( drawString, drawFont, drawBrush, drawRect );
   }
public void DrawStringRectangleF(PaintEventArgs e)
{
             
    // Create string to draw.
    String drawString = "Sample Text";
             
    // Create font and brush.
    Font drawFont = new Font("Arial", 16);
    SolidBrush drawBrush = new SolidBrush(Color.Black);
             
    // Create rectangle for drawing.
    float x = 150.0F;
    float y = 150.0F;
    float width = 200.0F;
    float height = 50.0F;
    RectangleF drawRect = new RectangleF(x, y, width, height);
             
    // Draw rectangle to screen.
    Pen blackPen = new Pen(Color.Black);
    e.Graphics.DrawRectangle(blackPen, x, y, width, height);
             
    // Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, drawRect);
}
Public Sub DrawStringRectangleF(ByVal e As PaintEventArgs)

    ' Create string to draw.
    Dim drawString As [String] = "Sample Text"

    ' Create font and brush.
    Dim drawFont As New Font("Arial", 16)
    Dim drawBrush As New SolidBrush(Color.Black)

    ' Create rectangle for drawing.
    Dim x As Single = 150.0F
    Dim y As Single = 150.0F
    Dim width As Single = 200.0F
    Dim height As Single = 50.0F
    Dim drawRect As New RectangleF(x, y, width, height)

    ' Draw rectangle to screen.
    Dim blackPen As New Pen(Color.Black)
    e.Graphics.DrawRectangle(blackPen, x, y, width, height)

    ' Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, drawRect)
End Sub

注釈

s パラメーターで表されるテキストは、layoutRectangle パラメーターで表される四角形内に描画されます。 テキストが四角形内に収まらない場合は、最も近い単語で切り捨てられます。 四角形内での文字列の描画方法をさらに操作するには、StringFormatを受け取るDrawStringオーバーロードを使用します。

こちらもご覧ください

適用対象

DrawString(String, Font, Brush, PointF)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定した Brush オブジェクトと Font オブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

public:
 void DrawString(System::String ^ s, System::Drawing::Font ^ font, System::Drawing::Brush ^ brush, System::Drawing::PointF point);
public void DrawString(string? s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.PointF point);
public void DrawString(string s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.PointF point);
member this.DrawString : string * System.Drawing.Font * System.Drawing.Brush * System.Drawing.PointF -> unit
Public Sub DrawString (s As String, font As Font, brush As Brush, point As PointF)

パラメーター

s
String

描画する文字列。

font
Font

Font 文字列のテキスト形式を定義する

brush
Brush

Brush 描画されたテキストの色とテクスチャを決定する

point
PointF

PointF 描画されたテキストの左上隅を指定する構造体。

例外

brushnullです。

-又は-

snullです。

次のコード例は、Windows Formsで使用するように設計されており、PaintEventArgse が必要です。これは、Paint イベント ハンドラーのパラメーターです。 このコードは、次のアクションを実行します。

  • 描画するテキスト文字列を作成します。

  • フォントを Arial (16pt) として定義します。

  • 描画するソリッドの黒いブラシを作成します。

  • テキストを描画する左上隅のポイントを作成します。

  • フォント、ブラシ、および変換先のポイントを使用して、文字列を画面に描画します。

public:
   void DrawStringPointF( PaintEventArgs^ e )
   {
      // Create string to draw.
      String^ drawString = "Sample Text";

      // Create font and brush.
      System::Drawing::Font^ drawFont = gcnew System::Drawing::Font( "Arial",16 );
      SolidBrush^ drawBrush = gcnew SolidBrush( Color::Black );

      // Create point for upper-left corner of drawing.
      PointF drawPoint = PointF(150.0F,150.0F);

      // Draw string to screen.
      e->Graphics->DrawString( drawString, drawFont, drawBrush, drawPoint );
   }
public void DrawStringPointF(PaintEventArgs e)
{
             
    // Create string to draw.
    String drawString = "Sample Text";
             
    // Create font and brush.
    Font drawFont = new Font("Arial", 16);
    SolidBrush drawBrush = new SolidBrush(Color.Black);
             
    // Create point for upper-left corner of drawing.
    PointF drawPoint = new PointF(150.0F, 150.0F);
             
    // Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint);
}
Public Sub DrawStringPointF(ByVal e As PaintEventArgs)

    ' Create string to draw.
    Dim drawString As [String] = "Sample Text"

    ' Create font and brush.
    Dim drawFont As New Font("Arial", 16)
    Dim drawBrush As New SolidBrush(Color.Black)

    ' Create point for upper-left corner of drawing.
    Dim drawPoint As New PointF(150.0F, 150.0F)

    ' Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint)
End Sub

こちらもご覧ください

適用対象

DrawString(ReadOnlySpan<Char>, Font, Brush, RectangleF)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定した Brush オブジェクトと Font オブジェクトを使用して、指定した四角形に指定したテキスト文字列を描画します。

public:
 void DrawString(ReadOnlySpan<char> s, System::Drawing::Font ^ font, System::Drawing::Brush ^ brush, System::Drawing::RectangleF layoutRectangle);
public void DrawString(ReadOnlySpan<char> s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.RectangleF layoutRectangle);
member this.DrawString : ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Brush * System.Drawing.RectangleF -> unit
Public Sub DrawString (s As ReadOnlySpan(Of Char), font As Font, brush As Brush, layoutRectangle As RectangleF)

パラメーター

s
ReadOnlySpan<Char>

描画する文字列。

font
Font

Font 文字列のテキスト形式を定義する

brush
Brush

Brush 描画されたテキストの色とテクスチャを決定する

layoutRectangle
RectangleF

RectangleF 描画されたテキストの位置を指定する構造体。

注釈

s パラメーターで表されるテキストは、layoutRectangle パラメーターで表される四角形内に描画されます。 テキストが四角形内に収まらない場合は、最も近い単語で切り捨てられます。 四角形内での文字列の描画方法をさらに操作するには、StringFormatを受け取るDrawString(ReadOnlySpan<Char>, Font, Brush, RectangleF, StringFormat)オーバーロードを使用します。

適用対象

DrawString(ReadOnlySpan<Char>, Font, Brush, PointF)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定した Brush オブジェクトと Font オブジェクトを使用して、指定した位置に指定したテキスト文字列を描画します。

public:
 void DrawString(ReadOnlySpan<char> s, System::Drawing::Font ^ font, System::Drawing::Brush ^ brush, System::Drawing::PointF point);
public void DrawString(ReadOnlySpan<char> s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.PointF point);
member this.DrawString : ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Brush * System.Drawing.PointF -> unit
Public Sub DrawString (s As ReadOnlySpan(Of Char), font As Font, brush As Brush, point As PointF)

パラメーター

s
ReadOnlySpan<Char>

描画する文字列。

font
Font

Font 文字列のテキスト形式を定義する

brush
Brush

Brush 描画されたテキストの色とテクスチャを決定する

point
PointF

PointF 描画されたテキストの左上隅を指定する構造体。

適用対象

DrawString(ReadOnlySpan<Char>, Font, Brush, RectangleF, StringFormat)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定したBrushの書式設定属性を使用して、指定したFontStringFormatオブジェクトを使用して、指定した四角形に指定したテキスト文字列を描画します。

public:
 void DrawString(ReadOnlySpan<char> s, System::Drawing::Font ^ font, System::Drawing::Brush ^ brush, System::Drawing::RectangleF layoutRectangle, System::Drawing::StringFormat ^ format);
public void DrawString(ReadOnlySpan<char> s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.RectangleF layoutRectangle, System.Drawing.StringFormat? format);
member this.DrawString : ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Brush * System.Drawing.RectangleF * System.Drawing.StringFormat -> unit
Public Sub DrawString (s As ReadOnlySpan(Of Char), font As Font, brush As Brush, layoutRectangle As RectangleF, format As StringFormat)

パラメーター

s
ReadOnlySpan<Char>

描画する文字列。

font
Font

Font 文字列のテキスト形式を定義する

brush
Brush

Brush 描画されたテキストの色とテクスチャを決定する

layoutRectangle
RectangleF

RectangleF 描画されたテキストの位置を指定する構造体。

format
StringFormat

StringFormat 描画されたテキストに適用される書式属性 (行間や配置など) を指定します。

適用対象