GraphicsPath.AddString Método

Definición

Agrega una cadena de texto a este trazado.Adds a text string to this path.

Sobrecargas

AddString(String, FontFamily, Int32, Single, RectangleF, StringFormat)

Agrega una cadena de texto a este trazado.Adds a text string to this path.

AddString(String, FontFamily, Int32, Single, Rectangle, StringFormat)

Agrega una cadena de texto a este trazado.Adds a text string to this path.

AddString(String, FontFamily, Int32, Single, PointF, StringFormat)

Agrega una cadena de texto a este trazado.Adds a text string to this path.

AddString(String, FontFamily, Int32, Single, Point, StringFormat)

Agrega una cadena de texto a este trazado.Adds a text string to this path.

AddString(String, FontFamily, Int32, Single, RectangleF, StringFormat)

Agrega una cadena de texto a este trazado.Adds a text string to this path.

public:
 void AddString(System::String ^ s, System::Drawing::FontFamily ^ family, int style, float emSize, System::Drawing::RectangleF layoutRect, System::Drawing::StringFormat ^ format);
public void AddString (string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.RectangleF layoutRect, System.Drawing.StringFormat format);
member this.AddString : string * System.Drawing.FontFamily * int * single * System.Drawing.RectangleF * System.Drawing.StringFormat -> unit
Public Sub AddString (s As String, family As FontFamily, style As Integer, emSize As Single, layoutRect As RectangleF, format As StringFormat)

Parámetros

s
String

String que se va a sumar.The String to add.

family
FontFamily

FontFamily que representa el nombre de la fuente con la que se dibuja la prueba.A FontFamily that represents the name of the font with which the test is drawn.

style
Int32

Enumeración FontStyle que representa la información de estilo sobre el texto (negrita, cursiva, etc.).A FontStyle enumeration that represents style information about the text (bold, italic, and so on). Se debe convertir en un entero (vea el ejemplo de código más adelante en esta sección).This must be cast as an integer (see the example code later in this section).

emSize
Single

Alto del cuadrado Em que delimita el carácter.The height of the em square box that bounds the character.

layoutRect
RectangleF

RectangleF que representa el rectángulo que delimita el texto.A RectangleF that represents the rectangle that bounds the text.

format
StringFormat

StringFormat que especifica información sobre el formato de texto, como el interlineado y la alineación.A StringFormat that specifies text formatting information, such as line spacing and alignment.

Ejemplos

Para obtener un ejemplo, vea AddString(String, FontFamily, Int32, Single, Point, StringFormat).For an example, see AddString(String, FontFamily, Int32, Single, Point, StringFormat).

AddString(String, FontFamily, Int32, Single, Rectangle, StringFormat)

Agrega una cadena de texto a este trazado.Adds a text string to this path.

public:
 void AddString(System::String ^ s, System::Drawing::FontFamily ^ family, int style, float emSize, System::Drawing::Rectangle layoutRect, System::Drawing::StringFormat ^ format);
public void AddString (string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Rectangle layoutRect, System.Drawing.StringFormat format);
member this.AddString : string * System.Drawing.FontFamily * int * single * System.Drawing.Rectangle * System.Drawing.StringFormat -> unit
Public Sub AddString (s As String, family As FontFamily, style As Integer, emSize As Single, layoutRect As Rectangle, format As StringFormat)

Parámetros

s
String

String que se va a sumar.The String to add.

family
FontFamily

FontFamily que representa el nombre de la fuente con la que se dibuja la prueba.A FontFamily that represents the name of the font with which the test is drawn.

style
Int32

Enumeración FontStyle que representa la información de estilo sobre el texto (negrita, cursiva, etc.).A FontStyle enumeration that represents style information about the text (bold, italic, and so on). Se debe convertir en un entero (vea el ejemplo de código más adelante en esta sección).This must be cast as an integer (see the example code later in this section).

emSize
Single

Alto del cuadrado Em que delimita el carácter.The height of the em square box that bounds the character.

layoutRect
Rectangle

Rectangle que representa el rectángulo que delimita el texto.A Rectangle that represents the rectangle that bounds the text.

format
StringFormat

StringFormat que especifica información sobre el formato de texto, como el interlineado y la alineación.A StringFormat that specifies text formatting information, such as line spacing and alignment.

Ejemplos

Para obtener un ejemplo, vea AddString(String, FontFamily, Int32, Single, Point, StringFormat).For an example, see AddString(String, FontFamily, Int32, Single, Point, StringFormat).

AddString(String, FontFamily, Int32, Single, PointF, StringFormat)

Agrega una cadena de texto a este trazado.Adds a text string to this path.

public:
 void AddString(System::String ^ s, System::Drawing::FontFamily ^ family, int style, float emSize, System::Drawing::PointF origin, System::Drawing::StringFormat ^ format);
public void AddString (string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.PointF origin, System.Drawing.StringFormat format);
member this.AddString : string * System.Drawing.FontFamily * int * single * System.Drawing.PointF * System.Drawing.StringFormat -> unit
Public Sub AddString (s As String, family As FontFamily, style As Integer, emSize As Single, origin As PointF, format As StringFormat)

Parámetros

s
String

String que se va a sumar.The String to add.

family
FontFamily

FontFamily que representa el nombre de la fuente con la que se dibuja la prueba.A FontFamily that represents the name of the font with which the test is drawn.

style
Int32

Enumeración FontStyle que representa la información de estilo sobre el texto (negrita, cursiva, etc.).A FontStyle enumeration that represents style information about the text (bold, italic, and so on). Se debe convertir en un entero (vea el ejemplo de código más adelante en esta sección).This must be cast as an integer (see the example code later in this section).

emSize
Single

Alto del cuadrado Em que delimita el carácter.The height of the em square box that bounds the character.

origin
PointF

PointF que representa el punto donde comienza el texto.A PointF that represents the point where the text starts.

format
StringFormat

StringFormat que especifica información sobre el formato de texto, como el interlineado y la alineación.A StringFormat that specifies text formatting information, such as line spacing and alignment.

Ejemplos

Para obtener un ejemplo, vea AddString(String, FontFamily, Int32, Single, Point, StringFormat).For an example, see AddString(String, FontFamily, Int32, Single, Point, StringFormat).

AddString(String, FontFamily, Int32, Single, Point, StringFormat)

Agrega una cadena de texto a este trazado.Adds a text string to this path.

public:
 void AddString(System::String ^ s, System::Drawing::FontFamily ^ family, int style, float emSize, System::Drawing::Point origin, System::Drawing::StringFormat ^ format);
public void AddString (string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Point origin, System.Drawing.StringFormat format);
member this.AddString : string * System.Drawing.FontFamily * int * single * System.Drawing.Point * System.Drawing.StringFormat -> unit
Public Sub AddString (s As String, family As FontFamily, style As Integer, emSize As Single, origin As Point, format As StringFormat)

Parámetros

s
String

String que se va a sumar.The String to add.

family
FontFamily

FontFamily que representa el nombre de la fuente con la que se dibuja la prueba.A FontFamily that represents the name of the font with which the test is drawn.

style
Int32

Enumeración FontStyle que representa la información de estilo sobre el texto (negrita, cursiva, etc.).A FontStyle enumeration that represents style information about the text (bold, italic, and so on). Se debe convertir en un entero (vea el ejemplo de código más adelante en esta sección).This must be cast as an integer (see the example code later in this section).

emSize
Single

Alto del cuadrado Em que delimita el carácter.The height of the em square box that bounds the character.

origin
Point

Point que representa el punto donde comienza el texto.A Point that represents the point where the text starts.

format
StringFormat

StringFormat que especifica información sobre el formato de texto, como el interlineado y la alineación.A StringFormat that specifies text formatting information, such as line spacing and alignment.

Ejemplos

El siguiente ejemplo de código está diseñado para su uso con Windows Forms y requiere PaintEventArgse, un objeto de evento de OnPaint.The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, an OnPaint event object. El código realiza las siguientes acciones:The code performs the following actions:

  • Crea una ruta de acceso.Creates a path.

  • Configura argumentos de cadena y fuente.Sets up string and font arguments.

  • Agrega la cadena a la ruta de acceso.Adds the string to the path.

  • Dibuja la cadena en la pantalla.Draws the string to the screen.

Hay dos aspectos importantes que se deben señalar. En primer lugar, observe que el argumento fontStyle se convierte en un entero.There are two important things to be pointed out. First, notice that the fontStyle argument is cast as an integer. El método AddString requiere esto para que se puedan combinar dos o más miembros de FontStyle para crear el estilo de fuente deseado (en este caso, Italic y Underline).The AddString method requires this so that two or more FontStyle members can be combined to create the desired font style (in this case, Italic and Underline). En segundo lugar, observe que se usa el método FillPath en lugar del método DrawPath.Secondly, notice that the FillPath method is used rather than the DrawPath method. Si se utiliza FillPath, se representa el texto sólido, mientras que si se usa DrawPath, el texto será un estilo de contorno.If FillPath is used, solid text is rendered, whereas if DrawPath is used, the text will be an outline style.

private:
   void AddStringExample( PaintEventArgs^ e )
   {
      // Create a GraphicsPath object.
      GraphicsPath^ myPath = gcnew GraphicsPath;

      // Set up all the string parameters.
      String^ stringText = "Sample Text";
      FontFamily^ family = gcnew FontFamily( "Arial" );
      int fontStyle = (int)FontStyle::Italic;
      int emSize = 26;
      Point origin = Point(20,20);
      StringFormat^ format = StringFormat::GenericDefault;

      // Add the string to the path.
      myPath->AddString( stringText, family, fontStyle, (float)emSize, origin, format );

      //Draw the path to the screen.
      e->Graphics->FillPath( Brushes::Black, myPath );
   }
private void AddStringExample(PaintEventArgs e)
{
             
    // Create a GraphicsPath object.
    GraphicsPath myPath = new GraphicsPath();
             
    // Set up all the string parameters.
    string stringText = "Sample Text";
    FontFamily family = new FontFamily("Arial");
    int fontStyle = (int)FontStyle.Italic;
    int emSize = 26;
    Point origin = new Point(20, 20);
    StringFormat format = StringFormat.GenericDefault;
             
    // Add the string to the path.
    myPath.AddString(stringText,
        family,
        fontStyle,
        emSize,
        origin,
        format);
             
    //Draw the path to the screen.
    e.Graphics.FillPath(Brushes.Black, myPath);
}
Public Sub AddStringExample(ByVal e As PaintEventArgs)

    ' Create a GraphicsPath object.
    Dim myPath As New GraphicsPath

    ' Set up all the string parameters.
    Dim stringText As String = "Sample Text"
    Dim family As New FontFamily("Arial")
    Dim myfontStyle As Integer = CInt(FontStyle.Italic)
    Dim emSize As Integer = 26
    Dim origin As New Point(20, 20)
    Dim format As StringFormat = StringFormat.GenericDefault

    ' Add the string to the path.
    myPath.AddString(stringText, family, myfontStyle, emSize, _
    origin, format)

    'Draw the path to the screen.
    e.Graphics.FillPath(Brushes.Black, myPath)
End Sub

Se aplica a