Graphics.DrawString Metoda

Definicja

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i Font .

Przeciążenia

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

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i Font przy użyciu atrybutów formatowania określonego StringFormatobiektu .

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

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i Font przy użyciu atrybutów formatowania określonego StringFormatobiektu .

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

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i Font .

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

Rysuje określony ciąg tekstowy w określonym prostokątze z określonymi Brush obiektami i Font przy użyciu atrybutów formatowania określonego StringFormat.

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

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i Font przy użyciu atrybutów formatowania określonego StringFormatobiektu .

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

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i Font .

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

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i Font przy użyciu atrybutów formatowania określonego StringFormatobiektu .

DrawString(String, Font, Brush, RectangleF)

Rysuje określony ciąg tekstowy w określonym prostokątze z określonymi Brush obiektami i Font .

DrawString(String, Font, Brush, PointF)

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i Font .

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

Rysuje określony ciąg tekstowy w określonym prostokątze z określonymi Brush obiektami i Font .

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

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i Font .

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

Rysuje określony ciąg tekstowy w określonym prostokątze z określonymi Brush obiektami i Font przy użyciu atrybutów formatowania określonego StringFormat.

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

Źródło:
Graphics.cs
Źródło:
Graphics.cs
Źródło:
Graphics.cs

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i Font przy użyciu atrybutów formatowania określonego StringFormatobiektu .

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)

Parametry

s
String

Ciąg do rysowania.

font
Font

Font definiujący format tekstowy ciągu.

brush
Brush

Brush określa kolor i teksturę tekstu narysowanego.

x
Single

Współrzędna x lewego górnego rogu narysowanego tekstu.

y
Single

Współrzędna y lewego górnego rogu narysowanego tekstu.

format
StringFormat

StringFormat określa atrybuty formatowania, takie jak odstępy między wierszami i wyrównanie, które są stosowane do tekstu rysowanego.

Wyjątki

brush to null.

-lub-

s to null.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgseparametru Paint programu obsługi zdarzeń. Kod wykonuje następujące akcje:

  • Tworzy ciąg tekstowy do rysowania.

  • Definiuje czcionkę jako Arial (16 pkt).

  • Tworzy solidną, czarną szczotkę do rysowania.

  • Tworzy współrzędne punktu dla lewego górnego rogu, w którym ma być rysowanie tekstu.

  • Ustawia format ciągu do rysowania w pionie

  • Rysuje ciąg na ekran przy użyciu czcionki, pędzla, punktu docelowego i formatu.

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

Zobacz też

Dotyczy

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

Źródło:
Graphics.cs
Źródło:
Graphics.cs

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i Font przy użyciu atrybutów formatowania określonego StringFormatobiektu .

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)

Parametry

s
ReadOnlySpan<Char>

Ciąg do rysowania.

font
Font

Font definiujący format tekstowy ciągu.

brush
Brush

Brush określa kolor i teksturę tekstu narysowanego.

x
Single

Współrzędna x lewego górnego rogu narysowanego tekstu.

y
Single

Współrzędna y lewego górnego rogu narysowanego tekstu.

format
StringFormat

StringFormat określa atrybuty formatowania, takie jak odstępy między wierszami i wyrównanie, które są stosowane do tekstu rysowanego.

Dotyczy

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

Źródło:
Graphics.cs
Źródło:
Graphics.cs
Źródło:
Graphics.cs

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i 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)

Parametry

s
String

Ciąg do rysowania.

font
Font

Font definiujący format tekstowy ciągu.

brush
Brush

Brush określa kolor i teksturę tekstu narysowanego.

x
Single

Współrzędna x lewego górnego rogu narysowanego tekstu.

y
Single

Współrzędna y lewego górnego rogu narysowanego tekstu.

Wyjątki

brush to null.

-lub-

s to null.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgseparametru Paint programu obsługi zdarzeń. Kod wykonuje następujące akcje:

  • Tworzy ciąg tekstowy do rysowania.

  • Definiuje czcionkę jako Arial (16 pkt).

  • Tworzy solidny czarny pędzl do rysowania.

  • Tworzy punkt dla lewego górnego rogu, w którym ma być rysowanie tekstu.

  • Rysuje ciąg na ekran przy użyciu czcionki, pędzla i punktu docelowego.

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

Zobacz też

Dotyczy

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

Źródło:
Graphics.cs
Źródło:
Graphics.cs
Źródło:
Graphics.cs

Rysuje określony ciąg tekstowy w określonym prostokątze z określonymi Brush obiektami i Font przy użyciu atrybutów formatowania określonego 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)

Parametry

s
String

Ciąg do rysowania.

font
Font

Font definiujący format tekstowy ciągu.

brush
Brush

Brush określa kolor i teksturę tekstu narysowanego.

layoutRectangle
RectangleF

RectangleF struktura określająca lokalizację tekstu narysowanego.

format
StringFormat

StringFormat określa atrybuty formatowania, takie jak odstępy między wierszami i wyrównanie, które są stosowane do tekstu rysowanego.

Wyjątki

brush to null.

-lub-

s to null.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgseparametru Paint programu obsługi zdarzeń. Kod wykonuje następujące akcje:

  • Tworzy ciąg tekstowy do rysowania.

  • Definiuje czcionkę jako Arial (16 pkt).

  • Tworzy solidną, czarną szczotkę do rysowania.

  • Tworzy prostokąt, w którym ma być rysowanie tekstu.

  • Rysuje prostokąt na ekranie.

  • Ustawia format ciągu, aby wyśrodkować go w prostokącie.

  • Rysuje ciąg na ekranie przy użyciu czcionki, pędzla i prostokąta docelowego.

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

Uwagi

Tekst reprezentowany przez s parametr jest rysowany wewnątrz prostokąta reprezentowanego layoutRectangle przez parametr . Jeśli tekst nie mieści się wewnątrz prostokąta, zostanie obcięty w najbliższym słowie, chyba że określono inaczej z parametrem format .

Zobacz też

Dotyczy

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

Źródło:
Graphics.cs
Źródło:
Graphics.cs
Źródło:
Graphics.cs

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i Font przy użyciu atrybutów formatowania określonego StringFormatelementu .

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)

Parametry

s
String

Ciąg do rysowania.

font
Font

Font definiuje format tekstowy ciągu.

brush
Brush

Brush określa kolor i teksturę rysowanego tekstu.

point
PointF

PointF struktura określająca lewy górny róg rysowanego tekstu.

format
StringFormat

StringFormat określa atrybuty formatowania, takie jak odstępy między wierszami i wyrównanie, które są stosowane do rysowanego tekstu.

Wyjątki

brush to null.

-lub-

s to null.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgseparametru Paint programu obsługi zdarzeń. Kod wykonuje następujące akcje:

  • Tworzy ciąg tekstowy do rysowania.

  • Definiuje czcionkę jako Arial (16 pkt).

  • Tworzy solidną, czarną szczotkę do rysowania.

  • Tworzy punkt dla lewego górnego rogu, w którym ma być rysowanie tekstu.

  • Ustawia format ciągu do rysowania w pionie.

  • Rysuje ciąg na ekranie przy użyciu czcionki, pędzla, punktu docelowego i formatu.

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

Zobacz też

Dotyczy

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

Źródło:
Graphics.cs
Źródło:
Graphics.cs

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i 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)

Parametry

s
ReadOnlySpan<Char>

Ciąg do rysowania.

font
Font

Font definiuje format tekstowy ciągu.

brush
Brush

Brush określa kolor i teksturę rysowanego tekstu.

x
Single

Współrzędna x lewego górnego rogu rysowanego tekstu.

y
Single

Współrzędna y lewego górnego rogu rysowanego tekstu.

Dotyczy

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

Źródło:
Graphics.cs
Źródło:
Graphics.cs

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i Font przy użyciu atrybutów formatowania określonego StringFormatelementu .

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)

Parametry

s
ReadOnlySpan<Char>

Ciąg do rysowania.

font
Font

Font definiuje format tekstowy ciągu.

brush
Brush

Brush określa kolor i teksturę rysowanego tekstu.

point
PointF

PointF struktura określająca lewy górny róg rysowanego tekstu.

format
StringFormat

StringFormat określa atrybuty formatowania, takie jak odstępy między wierszami i wyrównanie, które są stosowane do rysowanego tekstu.

Dotyczy

DrawString(String, Font, Brush, RectangleF)

Źródło:
Graphics.cs
Źródło:
Graphics.cs
Źródło:
Graphics.cs

Rysuje określony ciąg tekstowy w określonym prostokątze z określonymi Brush obiektami i 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)

Parametry

s
String

Ciąg do rysowania.

font
Font

Font definiuje format tekstowy ciągu.

brush
Brush

Brush określa kolor i teksturę rysowanego tekstu.

layoutRectangle
RectangleF

RectangleF struktura określająca lokalizację rysowanego tekstu.

Wyjątki

brush to null.

-lub-

s to null.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgseparametru Paint programu obsługi zdarzeń. Kod wykonuje następujące akcje:

  • Tworzy ciąg tekstowy do rysowania.

  • Definiuje czcionkę jako Arial (16 pkt).

  • Tworzy solidny, czarny pędzel do rysowania.

  • Tworzy prostokąt, w którym ma być rysowanie tekstu.

  • Rysuje prostokąt do ekranu.

  • Rysuje ciąg na ekranie przy użyciu czcionki, pędzla i prostokąta docelowego.

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

Uwagi

Tekst reprezentowany s przez parametr jest rysowany wewnątrz prostokąta reprezentowanego layoutRectangle przez parametr . Jeśli tekst nie mieści się wewnątrz prostokąta, zostanie obcięty w najbliższym słowie. Aby dodatkowo manipulować sposobem narysowania ciągu wewnątrz prostokąta, użyj DrawString przeciążenia, które przyjmuje StringFormatwartość .

Zobacz też

Dotyczy

DrawString(String, Font, Brush, PointF)

Źródło:
Graphics.cs
Źródło:
Graphics.cs
Źródło:
Graphics.cs

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i 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)

Parametry

s
String

Ciąg do rysowania.

font
Font

Font definiuje format tekstowy ciągu.

brush
Brush

Brush określa kolor i teksturę rysowanego tekstu.

point
PointF

PointF struktura określająca lewy górny róg rysowanego tekstu.

Wyjątki

brush to null.

-lub-

s to null.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgseparametru Paint programu obsługi zdarzeń. Kod wykonuje następujące akcje:

  • Tworzy ciąg tekstowy do rysowania.

  • Definiuje czcionkę jako Arial (16 pkt).

  • Tworzy solidny, czarny pędzel do rysowania.

  • Tworzy punkt dla lewego górnego rogu, w którym ma być rysowanie tekstu.

  • Rysuje ciąg na ekranie przy użyciu czcionki, pędzla i punktu docelowego.

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

Zobacz też

Dotyczy

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

Źródło:
Graphics.cs
Źródło:
Graphics.cs

Rysuje określony ciąg tekstowy w określonym prostokątze z określonymi Brush obiektami i 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)

Parametry

s
ReadOnlySpan<Char>

Ciąg do rysowania.

font
Font

Font definiuje format tekstowy ciągu.

brush
Brush

Brush określa kolor i teksturę rysowanego tekstu.

layoutRectangle
RectangleF

RectangleF struktura określająca lokalizację rysowanego tekstu.

Uwagi

Tekst reprezentowany s przez parametr jest rysowany wewnątrz prostokąta reprezentowanego layoutRectangle przez parametr . Jeśli tekst nie mieści się wewnątrz prostokąta, zostanie obcięty w najbliższym słowie. Aby dodatkowo manipulować sposobem narysowania ciągu wewnątrz prostokąta, użyj DrawString(ReadOnlySpan<Char>, Font, Brush, RectangleF, StringFormat) przeciążenia, które przyjmuje StringFormatwartość .

Dotyczy

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

Źródło:
Graphics.cs
Źródło:
Graphics.cs

Rysuje określony ciąg tekstowy w określonej lokalizacji z określonymi Brush obiektami i 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)

Parametry

s
ReadOnlySpan<Char>

Ciąg do rysowania.

font
Font

Font definiuje format tekstowy ciągu.

brush
Brush

Brush określa kolor i teksturę rysowanego tekstu.

point
PointF

PointF struktura określająca lewy górny róg rysowanego tekstu.

Dotyczy

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

Źródło:
Graphics.cs
Źródło:
Graphics.cs

Rysuje określony ciąg tekstowy w określonym prostokącie z określonymi Brush obiektami i Font przy użyciu atrybutów formatowania określonego StringFormatobiektu .

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)

Parametry

s
ReadOnlySpan<Char>

Ciąg do rysowania.

font
Font

Font definiuje format tekstowy ciągu.

brush
Brush

Brush określa kolor i teksturę rysowanego tekstu.

layoutRectangle
RectangleF

RectangleF struktura określająca lokalizację rysowanego tekstu.

format
StringFormat

StringFormat określa atrybuty formatowania, takie jak odstępy między wierszami i wyrównanie, które są stosowane do rysowanego tekstu.

Dotyczy