Graphics.DrawString Metodo

Definizione

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati.

Overload

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

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati, usando gli attributi di formattazione dell'oggetto StringFormat specificato.

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

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati, usando gli attributi di formattazione dell'oggetto StringFormat specificato.

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

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati.

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

Disegna la stringa di testo specificata nel rettangolo specificato con gli oggetti Brush e Font indicati, usando gli attributi di formattazione dell'oggetto StringFormat specificato.

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

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati, usando gli attributi di formattazione dell'oggetto StringFormat specificato.

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

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati.

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

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati, usando gli attributi di formattazione dell'oggetto StringFormat specificato.

DrawString(String, Font, Brush, RectangleF)

Disegna la stringa di testo specificata nel rettangolo specificato e con gli oggetti Brush e Font indicati.

DrawString(String, Font, Brush, PointF)

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati.

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

Disegna la stringa di testo specificata nel rettangolo specificato e con gli oggetti Brush e Font indicati.

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

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati.

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

Disegna la stringa di testo specificata nel rettangolo specificato con gli oggetti Brush e Font indicati, usando gli attributi di formattazione dell'oggetto StringFormat specificato.

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

Origine:
Graphics.cs
Origine:
Graphics.cs
Origine:
Graphics.cs

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati, usando gli attributi di formattazione dell'oggetto StringFormat specificato.

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)

Parametri

s
String

Stringa da disegnare.

font
Font

Oggetto Font che definisce il formato di testo della stringa.

brush
Brush

Oggetto Brush che determina il colore e la trama del testo disegnato.

x
Single

Coordinata X dell'angolo superiore sinistro del testo disegnato.

y
Single

Coordinata Y dell'angolo superiore sinistro del testo disegnato.

format
StringFormat

Oggetto StringFormat che specifica gli attributi di formattazione, quali l'interlinea e l'allineamento, applicati al testo disegnato.

Eccezioni

brush è null.

-oppure-

s è null.

Esempio

L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:

  • Crea una stringa di testo da disegnare.

  • Definisce il tipo di carattere come Arial (16pt).

  • Crea un pennello solido e nero da disegnare con.

  • Crea le coordinate di un punto per l'angolo superiore sinistro in corrispondenza del quale disegnare il testo.

  • Imposta il formato della stringa per disegnare verticalmente

  • Disegna la stringa sullo schermo usando il tipo di carattere, il pennello, il punto di destinazione e il formato.

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

Vedi anche

Si applica a

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

Origine:
Graphics.cs
Origine:
Graphics.cs

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati, usando gli attributi di formattazione dell'oggetto StringFormat specificato.

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)

Parametri

s
ReadOnlySpan<Char>

Stringa da disegnare.

font
Font

Oggetto Font che definisce il formato di testo della stringa.

brush
Brush

Oggetto Brush che determina il colore e la trama del testo disegnato.

x
Single

Coordinata X dell'angolo superiore sinistro del testo disegnato.

y
Single

Coordinata Y dell'angolo superiore sinistro del testo disegnato.

format
StringFormat

Oggetto StringFormat che specifica gli attributi di formattazione, quali l'interlinea e l'allineamento, applicati al testo disegnato.

Si applica a

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

Origine:
Graphics.cs
Origine:
Graphics.cs
Origine:
Graphics.cs

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati.

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)

Parametri

s
String

Stringa da disegnare.

font
Font

Oggetto Font che definisce il formato di testo della stringa.

brush
Brush

Oggetto Brush che determina il colore e la trama del testo disegnato.

x
Single

Coordinata X dell'angolo superiore sinistro del testo disegnato.

y
Single

Coordinata Y dell'angolo superiore sinistro del testo disegnato.

Eccezioni

brush è null.

-oppure-

s è null.

Esempio

L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:

  • Crea una stringa di testo da disegnare.

  • Definisce il tipo di carattere come Arial (16pt).

  • Crea un pennello nero solido con cui disegnare.

  • Crea un punto per l'angolo superiore sinistro in corrispondenza del quale disegnare il testo.

  • Disegna la stringa sullo schermo usando il tipo di carattere, il pennello e il punto di destinazione.

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

Vedi anche

Si applica a

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

Origine:
Graphics.cs
Origine:
Graphics.cs
Origine:
Graphics.cs

Disegna la stringa di testo specificata nel rettangolo specificato con gli oggetti Brush e Font indicati, usando gli attributi di formattazione dell'oggetto StringFormat specificato.

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)

Parametri

s
String

Stringa da disegnare.

font
Font

Oggetto Font che definisce il formato di testo della stringa.

brush
Brush

Oggetto Brush che determina il colore e la trama del testo disegnato.

layoutRectangle
RectangleF

Struttura RectangleF che specifica la posizione del testo disegnato.

format
StringFormat

Oggetto StringFormat che specifica gli attributi di formattazione, quali l'interlinea e l'allineamento, applicati al testo disegnato.

Eccezioni

brush è null.

-oppure-

s è null.

Esempio

L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:

  • Crea una stringa di testo da disegnare.

  • Definisce il tipo di carattere come Arial (16pt).

  • Crea un pennello solido e nero da disegnare con.

  • Crea un rettangolo in cui disegnare il testo.

  • Disegna il rettangolo sullo schermo.

  • Imposta il formato della stringa per centrarlo all'interno del rettangolo.

  • Disegna la stringa sullo schermo usando il tipo di carattere, il pennello e il rettangolo di destinazione.

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

Commenti

Il testo rappresentato dal s parametro viene disegnato all'interno del layoutRectangle rettangolo rappresentato dal parametro . Se il testo non si adatta all'interno del rettangolo, viene troncato nella parola più vicina, a meno che non venga specificato diversamente con il format parametro.

Vedi anche

Si applica a

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

Origine:
Graphics.cs
Origine:
Graphics.cs
Origine:
Graphics.cs

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati, usando gli attributi di formattazione dell'oggetto StringFormat specificato.

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)

Parametri

s
String

Stringa da disegnare.

font
Font

Oggetto Font che definisce il formato di testo della stringa.

brush
Brush

Oggetto Brush che determina il colore e la trama del testo disegnato.

point
PointF

Struttura PointF che rappresenta l'angolo superiore sinistro del testo disegnato.

format
StringFormat

Oggetto StringFormat che specifica gli attributi di formattazione, quali l'interlinea e l'allineamento, applicati al testo disegnato.

Eccezioni

brush è null.

-oppure-

s è null.

Esempio

L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:

  • Crea una stringa di testo da disegnare.

  • Definisce il tipo di carattere come Arial (16pt).

  • Crea un pennello solido e nero da disegnare con.

  • Crea un punto per l'angolo superiore sinistro in corrispondenza del quale disegnare il testo.

  • Imposta il formato della stringa per disegnare verticalmente.

  • Disegna la stringa sullo schermo usando il tipo di carattere, il pennello, il punto di destinazione e il formato.

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

Vedi anche

Si applica a

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

Origine:
Graphics.cs
Origine:
Graphics.cs

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati.

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)

Parametri

s
ReadOnlySpan<Char>

Stringa da disegnare.

font
Font

Oggetto Font che definisce il formato di testo della stringa.

brush
Brush

Oggetto Brush che determina il colore e la trama del testo disegnato.

x
Single

Coordinata X dell'angolo superiore sinistro del testo disegnato.

y
Single

Coordinata Y dell'angolo superiore sinistro del testo disegnato.

Si applica a

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

Origine:
Graphics.cs
Origine:
Graphics.cs

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati, usando gli attributi di formattazione dell'oggetto StringFormat specificato.

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)

Parametri

s
ReadOnlySpan<Char>

Stringa da disegnare.

font
Font

Oggetto Font che definisce il formato di testo della stringa.

brush
Brush

Oggetto Brush che determina il colore e la trama del testo disegnato.

point
PointF

Struttura PointF che rappresenta l'angolo superiore sinistro del testo disegnato.

format
StringFormat

Oggetto StringFormat che specifica gli attributi di formattazione, quali l'interlinea e l'allineamento, applicati al testo disegnato.

Si applica a

DrawString(String, Font, Brush, RectangleF)

Origine:
Graphics.cs
Origine:
Graphics.cs
Origine:
Graphics.cs

Disegna la stringa di testo specificata nel rettangolo specificato e con gli oggetti Brush e Font indicati.

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)

Parametri

s
String

Stringa da disegnare.

font
Font

Oggetto Font che definisce il formato di testo della stringa.

brush
Brush

Oggetto Brush che determina il colore e la trama del testo disegnato.

layoutRectangle
RectangleF

Struttura RectangleF che specifica la posizione del testo disegnato.

Eccezioni

brush è null.

-oppure-

s è null.

Esempio

L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:

  • Crea una stringa di testo da disegnare.

  • Definisce il tipo di carattere come Arial (16pt).

  • Crea un pennello solido e nero da disegnare con.

  • Crea un rettangolo in cui disegnare il testo.

  • Disegna il rettangolo sullo schermo.

  • Disegna la stringa sullo schermo usando il tipo di carattere, il pennello e il rettangolo di destinazione.

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

Commenti

Il testo rappresentato dal s parametro viene disegnato all'interno del layoutRectangle rettangolo rappresentato dal parametro . Se il testo non si adatta all'interno del rettangolo, viene troncato alla parola più vicina. Per modificare ulteriormente la modalità di disegno della stringa all'interno del rettangolo, usare l'overload DrawString che accetta un StringFormatoggetto .

Vedi anche

Si applica a

DrawString(String, Font, Brush, PointF)

Origine:
Graphics.cs
Origine:
Graphics.cs
Origine:
Graphics.cs

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati.

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)

Parametri

s
String

Stringa da disegnare.

font
Font

Oggetto Font che definisce il formato di testo della stringa.

brush
Brush

Oggetto Brush che determina il colore e la trama del testo disegnato.

point
PointF

Struttura PointF che rappresenta l'angolo superiore sinistro del testo disegnato.

Eccezioni

brush è null.

-oppure-

s è null.

Esempio

L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:

  • Crea una stringa di testo da disegnare.

  • Definisce il tipo di carattere come Arial (16pt).

  • Crea un pennello solido e nero da disegnare con.

  • Crea un punto per l'angolo superiore sinistro in corrispondenza del quale disegnare il testo.

  • Disegna la stringa sullo schermo usando il tipo di carattere, il pennello e il punto di destinazione.

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

Vedi anche

Si applica a

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

Origine:
Graphics.cs
Origine:
Graphics.cs

Disegna la stringa di testo specificata nel rettangolo specificato e con gli oggetti Brush e Font indicati.

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)

Parametri

s
ReadOnlySpan<Char>

Stringa da disegnare.

font
Font

Oggetto Font che definisce il formato di testo della stringa.

brush
Brush

Oggetto Brush che determina il colore e la trama del testo disegnato.

layoutRectangle
RectangleF

Struttura RectangleF che specifica la posizione del testo disegnato.

Commenti

Il testo rappresentato dal s parametro viene disegnato all'interno del layoutRectangle rettangolo rappresentato dal parametro . Se il testo non si adatta all'interno del rettangolo, viene troncato alla parola più vicina. Per modificare ulteriormente la modalità di disegno della stringa all'interno del rettangolo, usare l'overload DrawString(ReadOnlySpan<Char>, Font, Brush, RectangleF, StringFormat) che accetta un StringFormatoggetto .

Si applica a

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

Origine:
Graphics.cs
Origine:
Graphics.cs

Disegna la stringa di testo specificata nella posizione e con gli oggetti Brush e Font indicati.

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)

Parametri

s
ReadOnlySpan<Char>

Stringa da disegnare.

font
Font

Oggetto Font che definisce il formato di testo della stringa.

brush
Brush

Oggetto Brush che determina il colore e la trama del testo disegnato.

point
PointF

Struttura PointF che rappresenta l'angolo superiore sinistro del testo disegnato.

Si applica a

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

Origine:
Graphics.cs
Origine:
Graphics.cs

Disegna la stringa di testo specificata nel rettangolo specificato con gli oggetti Brush e Font indicati, usando gli attributi di formattazione dell'oggetto StringFormat specificato.

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)

Parametri

s
ReadOnlySpan<Char>

Stringa da disegnare.

font
Font

Oggetto Font che definisce il formato di testo della stringa.

brush
Brush

Oggetto Brush che determina il colore e la trama del testo disegnato.

layoutRectangle
RectangleF

Struttura RectangleF che specifica la posizione del testo disegnato.

format
StringFormat

Oggetto StringFormat che specifica gli attributi di formattazione, quali l'interlinea e l'allineamento, applicati al testo disegnato.

Si applica a