Freigeben über


GraphicsPath.AddString Methode

Definition

Fügt diesem Pfad eine Textzeichenfolge hinzu.

Überlädt

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

Fügt diesem Pfad eine Textzeichenfolge hinzu.

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

Fügt diesem Pfad eine Textzeichenfolge hinzu.

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

Fügt diesem Pfad eine Textzeichenfolge hinzu.

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

Fügt diesem Pfad eine Textzeichenfolge hinzu.

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

Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs

Fügt diesem Pfad eine Textzeichenfolge hinzu.

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);
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)

Parameter

s
String

Die hinzuzufügende String.

family
FontFamily

Ein FontFamily, der den Namen der Schriftart darstellt, mit der der Test gezeichnet wird.

style
Int32

Eine FontStyle Enumeration, die Formatvorlageninformationen zum Text darstellt (fett, kursiv usw.). Dies muss als ganze Zahl umgewandelt werden (siehe Beispielcode weiter unten in diesem Abschnitt).

emSize
Single

Die Höhe des quadratischen Felds, das das Zeichen begrenzt.

origin
Point

Ein Point, der den Punkt darstellt, an dem der Text beginnt.

format
StringFormat

Eine StringFormat, die Textformatierungsinformationen angibt, z. B. Zeilenabstand und Ausrichtung.

Beispiele

Das folgende Codebeispiel wurde für die Verwendung mit Windows Forms entwickelt und erfordert PaintEventArgse, ein OnPaint-Ereignisobjekt. Der Code führt die folgenden Aktionen aus:

  • Erstellt einen Pfad.

  • Richtet Zeichenfolgen- und Schriftartargumente ein.

  • Fügt die Zeichenfolge zum Pfad hinzu.

  • Zeichnet die Zeichenfolge auf dem Bildschirm.

Es gibt zwei wichtige Punkte, auf die verwiesen werden muss. Beachten Sie zunächst, dass das argument fontStyle als ganze Zahl umgewandelt wird. Für die AddString-Methode ist dies erforderlich, damit zwei oder mehr FontStyle Elemente kombiniert werden können, um den gewünschten Schriftschnitt zu erstellen (in diesem Fall Italic und Underline). Beachten Sie zweitens, dass die FillPath-Methode anstelle der DrawPath-Methode verwendet wird. Wenn FillPath verwendet wird, wird Einfarbiger Text gerendert, während bei Verwendung DrawPath der Text eine Gliederungsformatvorlage ist.

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

Gilt für:

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

Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs

Fügt diesem Pfad eine Textzeichenfolge hinzu.

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);
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)

Parameter

s
String

Die hinzuzufügende String.

family
FontFamily

Ein FontFamily, der den Namen der Schriftart darstellt, mit der der Test gezeichnet wird.

style
Int32

Eine FontStyle Enumeration, die Formatvorlageninformationen zum Text darstellt (fett, kursiv usw.). Dies muss als ganze Zahl umgewandelt werden (siehe Beispielcode weiter unten in diesem Abschnitt).

emSize
Single

Die Höhe des quadratischen Felds, das das Zeichen begrenzt.

origin
PointF

Ein PointF, der den Punkt darstellt, an dem der Text beginnt.

format
StringFormat

Eine StringFormat, die Textformatierungsinformationen angibt, z. B. Zeilenabstand und Ausrichtung.

Beispiele

Ein Beispiel finden Sie unter AddString(String, FontFamily, Int32, Single, Point, StringFormat).

Gilt für:

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

Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs

Fügt diesem Pfad eine Textzeichenfolge hinzu.

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);
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)

Parameter

s
String

Die hinzuzufügende String.

family
FontFamily

Ein FontFamily, der den Namen der Schriftart darstellt, mit der der Test gezeichnet wird.

style
Int32

Eine FontStyle Enumeration, die Formatvorlageninformationen zum Text darstellt (fett, kursiv usw.). Dies muss als ganze Zahl umgewandelt werden (siehe Beispielcode weiter unten in diesem Abschnitt).

emSize
Single

Die Höhe des quadratischen Felds, das das Zeichen begrenzt.

layoutRect
Rectangle

Ein Rectangle, das das Rechteck darstellt, das den Text begrenzt.

format
StringFormat

Eine StringFormat, die Textformatierungsinformationen angibt, z. B. Zeilenabstand und Ausrichtung.

Beispiele

Ein Beispiel finden Sie unter AddString(String, FontFamily, Int32, Single, Point, StringFormat).

Gilt für:

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

Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs
Quelle:
GraphicsPath.cs

Fügt diesem Pfad eine Textzeichenfolge hinzu.

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);
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)

Parameter

s
String

Die hinzuzufügende String.

family
FontFamily

Ein FontFamily, der den Namen der Schriftart darstellt, mit der der Test gezeichnet wird.

style
Int32

Eine FontStyle Enumeration, die Formatvorlageninformationen zum Text darstellt (fett, kursiv usw.). Dies muss als ganze Zahl umgewandelt werden (siehe Beispielcode weiter unten in diesem Abschnitt).

emSize
Single

Die Höhe des quadratischen Felds, das das Zeichen begrenzt.

layoutRect
RectangleF

Ein RectangleF, das das Rechteck darstellt, das den Text begrenzt.

format
StringFormat

Eine StringFormat, die Textformatierungsinformationen angibt, z. B. Zeilenabstand und Ausrichtung.

Beispiele

Ein Beispiel finden Sie unter AddString(String, FontFamily, Int32, Single, Point, StringFormat).

Gilt für: