Freigeben über


StringFormat.ToString-Methode

Konvertiert dieses StringFormat-Objekt in eine Klartextzeichenfolge.

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

Syntax

'Declaration
Public Overrides Function ToString As String
'Usage
Dim instance As StringFormat
Dim returnValue As String

returnValue = instance.ToString
public override string ToString ()
public:
virtual String^ ToString () override
public String ToString ()
public override function ToString () : String

Rückgabewert

Eine Zeichenfolgenentsprechung dieses StringFormat-Objekts.

Hinweise

Lediglich der Wert der FormatFlags-Eigenschaft wird konvertiert.

Beispiel

Das folgende Beispiel ist für die Verwendung mit Windows Forms vorgesehen und erfordert PaintEventArgse, wobei es sich um einen Parameter des Paint-Ereignishandlers handelt. Der Code führt die folgenden Aktionen aus:

  • Konvertiert ein StringFormat-Objekt in eine Zeichenfolge.

  • Zeichnet die Zeichenfolge.

  • Ändert einige Eigenschaften des StringFormat-Objekts.

  • Zeichnet die Zeichenfolge. Dies ist eine andere Zeichenfolge, da sich die Eigenschaften des StringFormat-Objekts geändert haben.

Public Sub ToStringExample(ByVal e As PaintEventArgs)
    Dim g As Graphics = e.Graphics
    Dim blueBrush As New SolidBrush(Color.FromArgb(255, 0, 0, 255))
    Dim myFont As New Font("Times New Roman", 14)
    Dim myStringFormat As New StringFormat

    ' String variable to hold the values of the StringFormat object.
    Dim strFmtString As String

    ' Convert the string format object to a string (only certain
    ' information in the object is converted) and display the string.
    strFmtString = myStringFormat.ToString()
    g.DrawString("Before changing properties:   ", myFont, blueBrush, _
    20, 40, myStringFormat)

    ' Change some properties of the string format.
    myStringFormat.Trimming = StringTrimming.None
    myStringFormat.FormatFlags = StringFormatFlags.NoWrap Or _
    StringFormatFlags.NoClip

    ' Convert the string format object to a string and display the
    ' string. The string will be different because the properties of
    ' the string format have changed.
    strFmtString = myStringFormat.ToString()
    g.DrawString("After changing properties:   ", myFont, blueBrush, _
    20, 70, myStringFormat)
End Sub
public void ToStringExample(PaintEventArgs e)
{
    Graphics     g = e.Graphics;
    SolidBrush   blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255));
    Font         myFont = new Font("Times New Roman", 14);
    StringFormat myStringFormat = new StringFormat();
             
    // String variable to hold the values of the StringFormat object.
    string    strFmtString;
             
    // Convert the string format object to a string (only certain information
    // in the object is converted) and display the string.
    strFmtString = myStringFormat.ToString();
    g.DrawString("Before changing properties:   " + myStringFormat,
        myFont, blueBrush, 20, 40);
             
    // Change some properties of the string format
    myStringFormat.Trimming = StringTrimming.None;
    myStringFormat.FormatFlags =   StringFormatFlags.NoWrap
        | StringFormatFlags.NoClip;
             
    // Convert the string format object to a string and display the string.
    // The string will be different because the properties of the string
    // format have changed.
    strFmtString = myStringFormat.ToString();
    g.DrawString("After changing properties:   " + myStringFormat,
        myFont, blueBrush, 20, 70);
}
void ToStringExample( PaintEventArgs^ e )
{
   Graphics^ g = e->Graphics;
   SolidBrush^ blueBrush = gcnew SolidBrush( Color::FromArgb( 255, 0, 0, 255 ) );
   System::Drawing::Font^ myFont = gcnew System::Drawing::Font( "Times New Roman",14 );
   StringFormat^ myStringFormat = gcnew StringFormat;

   // String variable to hold the values of the StringFormat object.
   String^ strFmtString;

   // Convert the string format object to a string (only certain information
   // in the object is converted) and display the string.
   strFmtString = myStringFormat->ToString();
   g->DrawString( String::Format( "Before changing properties:   {0}", myStringFormat ), myFont, blueBrush, 20, 40 );

   // Change some properties of the string format
   myStringFormat->Trimming = StringTrimming::None;
   myStringFormat->FormatFlags = (StringFormatFlags)(StringFormatFlags::NoWrap | StringFormatFlags::NoClip);

   // Convert the string format object to a string and display the string.
   // The string will be different because the properties of the string
   // format have changed.
   strFmtString = myStringFormat->ToString();
   g->DrawString( String::Format( "After changing properties:   {0}", myStringFormat ), myFont, blueBrush, 20, 70 );
}
public void ToStringExample(PaintEventArgs e)
{
    Graphics g = e.get_Graphics();
    SolidBrush blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255));
    Font myFont = new Font("Times New Roman", 14);
    StringFormat myStringFormat = new StringFormat();

    // String variable to hold the values of the StringFormat object.
    String strFmtString;

    // Convert the string format object to a string (only certain 
    // information in the object is converted) and display the string.
    strFmtString = myStringFormat.ToString();
    g.DrawString("Before changing properties:   " + myStringFormat, myFont,
        blueBrush, 20, 40);

    // Change some properties of the string format
    myStringFormat.set_Trimming(StringTrimming.None);
    myStringFormat.set_FormatFlags(
        StringFormatFlags.NoWrap | StringFormatFlags.NoClip);

    // Convert the string format object to a string and display the string.
    // The string will be different because the properties of the string
    // format have changed.
    strFmtString = myStringFormat.ToString();
    g.DrawString("After changing properties:   " + myStringFormat, myFont,
        blueBrush, 20, 70);
} //ToStringExample

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0

Siehe auch

Referenz

StringFormat-Klasse
StringFormat-Member
System.Drawing-Namespace