Graphics.DrawString Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Surcharges
DrawString(String, Font, Brush, Single, Single, StringFormat) |
Dessine la chaîne de texte précisée à l'emplacement indiqué avec les objets Brush et Font spécifiés, à l'aide des attributs de mise en forme du StringFormat spécifié. |
DrawString(ReadOnlySpan<Char>, Font, Brush, Single, Single, StringFormat) |
Dessine la chaîne de texte précisée à l'emplacement indiqué avec les objets Brush et Font spécifiés, à l'aide des attributs de mise en forme du StringFormat spécifié. |
DrawString(String, Font, Brush, Single, Single) |
Dessine la chaîne de texte précisée à l'emplacement indiqué avec les objets Brush et Font spécifiés. |
DrawString(String, Font, Brush, RectangleF, StringFormat) |
Dessine la chaîne de texte précisée dans le rectangle indiqué avec les objets Brush et Font spécifiés, à l'aide des attributs de mise en forme du StringFormat spécifié. |
DrawString(String, Font, Brush, PointF, StringFormat) |
Dessine la chaîne de texte précisée à l'emplacement indiqué avec les objets Brush et Font spécifiés, à l'aide des attributs de mise en forme du StringFormat spécifié. |
DrawString(ReadOnlySpan<Char>, Font, Brush, Single, Single) |
Dessine la chaîne de texte précisée à l'emplacement indiqué avec les objets Brush et Font spécifiés. |
DrawString(ReadOnlySpan<Char>, Font, Brush, PointF, StringFormat) |
Dessine la chaîne de texte précisée à l'emplacement indiqué avec les objets Brush et Font spécifiés, à l'aide des attributs de mise en forme du StringFormat spécifié. |
DrawString(String, Font, Brush, RectangleF) |
Dessine la chaîne de texte précisée dans le rectangle indiqué avec les objets Brush et Font spécifiés. |
DrawString(String, Font, Brush, PointF) |
Dessine la chaîne de texte précisée à l'emplacement indiqué avec les objets Brush et Font spécifiés. |
DrawString(ReadOnlySpan<Char>, Font, Brush, RectangleF) |
Dessine la chaîne de texte précisée dans le rectangle indiqué avec les objets Brush et Font spécifiés. |
DrawString(ReadOnlySpan<Char>, Font, Brush, PointF) |
Dessine la chaîne de texte précisée à l'emplacement indiqué avec les objets Brush et Font spécifiés. |
DrawString(ReadOnlySpan<Char>, Font, Brush, RectangleF, StringFormat) |
Dessine la chaîne de texte précisée dans le rectangle indiqué avec les objets Brush et Font spécifiés, à l'aide des attributs de mise en forme du StringFormat spécifié. |
DrawString(String, Font, Brush, Single, Single, StringFormat)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
Dessine la chaîne de texte précisée à l'emplacement indiqué avec les objets Brush et Font spécifiés, à l'aide des attributs de mise en forme du StringFormat spécifié.
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)
Paramètres
- s
- String
Chaîne à dessiner.
- x
- Single
Coordonnée x de l'angle supérieur gauche du texte dessiné.
- y
- Single
Coordonnée y de l'angle supérieur gauche du texte dessiné.
- format
- StringFormat
StringFormat qui spécifie les attributs de mise en forme, tels que l'interligne et l'alignement, qui sont appliqués au texte dessiné.
Exceptions
Exemples
L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse
, qui est un paramètre du Paint gestionnaire d’événements. Le code effectue les actions suivantes :
Crée une chaîne de texte à dessiner.
Définit la police en tant que Arial (16pt).
Crée un pinceau noir uni avec qui dessiner.
Crée les coordonnées d’un point pour le coin supérieur gauche où dessiner le texte.
Définit le format de la chaîne à dessiner verticalement
Dessine la chaîne vers l’écran à l’aide de la police, du pinceau, du point de destination et du format.
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
Voir aussi
S’applique à
DrawString(ReadOnlySpan<Char>, Font, Brush, Single, Single, StringFormat)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
Dessine la chaîne de texte précisée à l'emplacement indiqué avec les objets Brush et Font spécifiés, à l'aide des attributs de mise en forme du StringFormat spécifié.
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)
Paramètres
- s
- ReadOnlySpan<Char>
Chaîne à dessiner.
- x
- Single
Coordonnée x de l'angle supérieur gauche du texte dessiné.
- y
- Single
Coordonnée y de l'angle supérieur gauche du texte dessiné.
- format
- StringFormat
StringFormat qui spécifie les attributs de mise en forme, tels que l'interligne et l'alignement, qui sont appliqués au texte dessiné.
S’applique à
DrawString(String, Font, Brush, Single, Single)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
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)
Paramètres
- s
- String
Chaîne à dessiner.
- x
- Single
Coordonnée x de l'angle supérieur gauche du texte dessiné.
- y
- Single
Coordonnée y de l'angle supérieur gauche du texte dessiné.
Exceptions
Exemples
L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse
, qui est un paramètre du Paint gestionnaire d’événements. Le code effectue les actions suivantes :
Crée une chaîne de texte à dessiner.
Définit la police en tant que Arial (16pt).
Crée un pinceau noir uni avec qui dessiner.
Crée un point pour le coin supérieur gauche à partir duquel dessiner le texte.
Dessine la chaîne vers l’écran à l’aide de la police, du pinceau et du point de destination.
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
Voir aussi
S’applique à
DrawString(String, Font, Brush, RectangleF, StringFormat)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
Dessine la chaîne de texte précisée dans le rectangle indiqué avec les objets Brush et Font spécifiés, à l'aide des attributs de mise en forme du StringFormat spécifié.
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)
Paramètres
- s
- String
Chaîne à dessiner.
- layoutRectangle
- RectangleF
Structure RectangleF qui spécifie l'emplacement du texte dessiné.
- format
- StringFormat
StringFormat qui spécifie les attributs de mise en forme, tels que l'interligne et l'alignement, qui sont appliqués au texte dessiné.
Exceptions
Exemples
L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse
, qui est un paramètre du Paint gestionnaire d’événements. Le code effectue les actions suivantes :
Crée une chaîne de texte à dessiner.
Définit la police en tant que Arial (16pt).
Crée un pinceau noir uni avec qui dessiner.
Crée un rectangle dans lequel dessiner le texte.
Dessine le rectangle vers l’écran.
Définit le format de la chaîne pour la centrer dans le rectangle.
Dessine la chaîne vers l’écran à l’aide de la police, du pinceau et du rectangle de destination.
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
Remarques
Le texte représenté par le s
paramètre est dessiné à l’intérieur du rectangle représenté par le layoutRectangle
paramètre. Si le texte ne tient pas à l’intérieur du rectangle, il est tronqué au mot le plus proche, sauf indication contraire avec le format
paramètre.
Voir aussi
S’applique à
DrawString(String, Font, Brush, PointF, StringFormat)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
Dessine la chaîne de texte précisée à l'emplacement indiqué avec les objets Brush et Font spécifiés, à l'aide des attributs de mise en forme du StringFormat spécifié.
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)
Paramètres
- s
- String
Chaîne à dessiner.
- format
- StringFormat
StringFormat qui spécifie les attributs de mise en forme, tels que l'interligne et l'alignement, qui sont appliqués au texte dessiné.
Exceptions
Exemples
L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse
, qui est un paramètre du Paint gestionnaire d’événements. Le code effectue les actions suivantes :
Crée une chaîne de texte à dessiner.
Définit la police en tant que Arial (16pt).
Crée un pinceau noir uni avec qui dessiner.
Crée un point pour le coin supérieur gauche à partir duquel dessiner le texte.
Définit le format de la chaîne à dessiner verticalement.
Dessine la chaîne vers l’écran à l’aide de la police, du pinceau, du point de destination et du format.
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
Voir aussi
S’applique à
DrawString(ReadOnlySpan<Char>, Font, Brush, Single, Single)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
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)
Paramètres
- s
- ReadOnlySpan<Char>
Chaîne à dessiner.
- x
- Single
Coordonnée x de l'angle supérieur gauche du texte dessiné.
- y
- Single
Coordonnée y de l'angle supérieur gauche du texte dessiné.
S’applique à
DrawString(ReadOnlySpan<Char>, Font, Brush, PointF, StringFormat)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
Dessine la chaîne de texte précisée à l'emplacement indiqué avec les objets Brush et Font spécifiés, à l'aide des attributs de mise en forme du StringFormat spécifié.
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)
Paramètres
- s
- ReadOnlySpan<Char>
Chaîne à dessiner.
- format
- StringFormat
StringFormat qui spécifie les attributs de mise en forme, tels que l'interligne et l'alignement, qui sont appliqués au texte dessiné.
S’applique à
DrawString(String, Font, Brush, RectangleF)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
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)
Paramètres
- s
- String
Chaîne à dessiner.
- layoutRectangle
- RectangleF
Structure RectangleF qui spécifie l'emplacement du texte dessiné.
Exceptions
Exemples
L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse
, qui est un paramètre du Paint gestionnaire d’événements. Le code effectue les actions suivantes :
Crée une chaîne de texte à dessiner.
Définit la police en tant que Arial (16pt).
Crée un pinceau noir uni avec qui dessiner.
Crée un rectangle dans lequel dessiner le texte.
Dessine le rectangle vers l’écran.
Dessine la chaîne vers l’écran à l’aide de la police, du pinceau et du rectangle de destination.
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
Remarques
Le texte représenté par le s
paramètre est dessiné à l’intérieur du rectangle représenté par le layoutRectangle
paramètre. Si le texte ne tient pas à l’intérieur du rectangle, il est tronqué au mot le plus proche. Pour manipuler davantage la façon dont la chaîne est dessinée à l’intérieur du rectangle, utilisez la DrawString surcharge qui prend un StringFormat.
Voir aussi
S’applique à
DrawString(String, Font, Brush, PointF)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
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)
Paramètres
- s
- String
Chaîne à dessiner.
Exceptions
Exemples
L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse
, qui est un paramètre du Paint gestionnaire d’événements. Le code effectue les actions suivantes :
Crée une chaîne de texte à dessiner.
Définit la police en tant que Arial (16pt).
Crée un pinceau noir uni avec qui dessiner.
Crée un point pour le coin supérieur gauche à partir duquel dessiner le texte.
Dessine la chaîne vers l’écran à l’aide de la police, du pinceau et du point de destination.
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
Voir aussi
S’applique à
DrawString(ReadOnlySpan<Char>, Font, Brush, RectangleF)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
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)
Paramètres
- s
- ReadOnlySpan<Char>
Chaîne à dessiner.
- layoutRectangle
- RectangleF
Structure RectangleF qui spécifie l'emplacement du texte dessiné.
Remarques
Le texte représenté par le s
paramètre est dessiné à l’intérieur du rectangle représenté par le layoutRectangle
paramètre. Si le texte ne tient pas à l’intérieur du rectangle, il est tronqué au mot le plus proche. Pour manipuler davantage la façon dont la chaîne est dessinée à l’intérieur du rectangle, utilisez la DrawString(ReadOnlySpan<Char>, Font, Brush, RectangleF, StringFormat) surcharge qui prend un StringFormat.
S’applique à
DrawString(ReadOnlySpan<Char>, Font, Brush, PointF)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
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)
Paramètres
- s
- ReadOnlySpan<Char>
Chaîne à dessiner.
S’applique à
DrawString(ReadOnlySpan<Char>, Font, Brush, RectangleF, StringFormat)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
Dessine la chaîne de texte précisée dans le rectangle indiqué avec les objets Brush et Font spécifiés, à l'aide des attributs de mise en forme du StringFormat spécifié.
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)
Paramètres
- s
- ReadOnlySpan<Char>
Chaîne à dessiner.
- layoutRectangle
- RectangleF
Structure RectangleF qui spécifie l'emplacement du texte dessiné.
- format
- StringFormat
StringFormat qui spécifie les attributs de mise en forme, tels que l'interligne et l'alignement, qui sont appliqués au texte dessiné.
S’applique à
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour