次の方法で共有


Graphics.DrawString メソッド (String, Font, Brush, Single, Single, StringFormat)

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

Overloads Public Sub DrawString( _
   ByVal s As String, _   ByVal font As Font, _   ByVal brush As Brush, _   ByVal x As Single, _   ByVal y As Single, _   ByVal format As StringFormat _)
[C#]
public void DrawString(strings,Fontfont,Brushbrush,floatx,floaty,StringFormatformat);
[C++]
public: void DrawString(String* s,Font* font,Brush* brush,floatx,floaty,StringFormat* format);
[JScript]
public function DrawString(
   s : String,font : Font,brush : Brush,x : float,y : float,format : StringFormat);

パラメータ

  • s
    描画する文字列。
  • font
    文字列のテキスト形式を定義する Font オブジェクト。
  • brush
    描画するテキストの色とテクスチャを決定する Brush オブジェクト。
  • x
    描画するテキストの左上隅の x 座標。
  • y
    描画するテキストの左上隅の y 座標。
  • format
    描画するテキストに適用する行間や配置などの書式属性を指定する StringFormat オブジェクト。

戻り値

このメソッドは値を返しません。

使用例

[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。

  • 描画する文字列を作成します。
  • フォントを Arial (16 ポイント) に定義します。
  • 描画に使用する黒いソリッド ブラシを作成します。
  • テキストを描画する左上隅の点の座標を作成します。
  • 垂直方向に描画する文字列の書式を設定します。
  • フォント、ブラシ、描画先の点、および書式を使用して、画面に文字列を描画します。
 
Public Sub DrawStringFloatFormat(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 = 150F
Dim y As Single = 50F
' 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
        
[C#] 
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);
}
        

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

Graphics クラス | Graphics メンバ | System.Drawing 名前空間 | Graphics.DrawString オーバーロードの一覧