Graphics.DrawString メソッド

定義

指定した位置に、指定した Brush オブジェクトと Font オブジェクトで、指定した文字列を描画します。

オーバーロード

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

指定した Brush の書式属性を使用して、指定した Font オブジェクトおよび StringFormat オブジェクトで、指定した位置に指定した文字列を描画します。

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

指定した Brush の書式属性を使用して、指定した Font オブジェクトおよび StringFormat オブジェクトで、指定した位置に指定した文字列を描画します。

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

指定した位置に、指定した Brush オブジェクトと Font オブジェクトで、指定した文字列を描画します。

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

指定した Brush の書式属性を使用して、指定した Font オブジェクトおよび StringFormat オブジェクトで、指定した四角形に指定した文字列を描画します。

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

指定した Brush の書式属性を使用して、指定した Font オブジェクトおよび StringFormat オブジェクトで、指定した位置に指定した文字列を描画します。

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

指定した位置に、指定した Brush オブジェクトと Font オブジェクトで、指定した文字列を描画します。

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

指定した Brush の書式属性を使用して、指定した Font オブジェクトおよび StringFormat オブジェクトで、指定した位置に指定した文字列を描画します。

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 の書式属性を使用して、指定した Font オブジェクトおよび StringFormat オブジェクトで、指定した四角形に指定した文字列を描画します。

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

指定した Brush の書式属性を使用して、指定した Font オブジェクトおよび StringFormat オブジェクトで、指定した位置に指定した文字列を描画します。

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 フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

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

  • フォントを 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)

指定した Brush の書式属性を使用して、指定した Font オブジェクトおよび StringFormat オブジェクトで、指定した位置に指定した文字列を描画します。

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)

指定した位置に、指定した 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 フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

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

  • フォントを 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)

指定した Brush の書式属性を使用して、指定した Font オブジェクトおよび StringFormat オブジェクトで、指定した四角形に指定した文字列を描画します。

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 フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

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

  • フォントを 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)

指定した Brush の書式属性を使用して、指定した Font オブジェクトおよび StringFormat オブジェクトで、指定した位置に指定した文字列を描画します。

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 フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

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

  • フォントを 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)

指定した位置に、指定した 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)

指定した Brush の書式属性を使用して、指定した Font オブジェクトおよび StringFormat オブジェクトで、指定した位置に指定した文字列を描画します。

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)

指定した 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 フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

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

  • フォントを 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 描画されます。 テキストが四角形内に収まらない場合は、最も近い単語で切り捨てられます。 四角形内での文字列の描画方法をさらに操作するには、 を DrawString 受け取るオーバーロードを StringFormat使用します。

こちらもご覧ください

適用対象

DrawString(String, Font, Brush, PointF)

指定した位置に、指定した 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 フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

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

  • フォントを 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)

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

適用対象

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

指定した位置に、指定した 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)

指定した Brush の書式属性を使用して、指定した Font オブジェクトおよび StringFormat オブジェクトで、指定した四角形に指定した文字列を描画します。

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

適用対象