Freigeben über


StringFormat.SetTabStops-Methode

Legt Tabstopps für dieses StringFormat-Objekt fest.

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

Syntax

'Declaration
Public Sub SetTabStops ( _
    firstTabOffset As Single, _
    tabStops As Single() _
)
'Usage
Dim instance As StringFormat
Dim firstTabOffset As Single
Dim tabStops As Single()

instance.SetTabStops(firstTabOffset, tabStops)
public void SetTabStops (
    float firstTabOffset,
    float[] tabStops
)
public:
void SetTabStops (
    float firstTabOffset, 
    array<float>^ tabStops
)
public void SetTabStops (
    float firstTabOffset, 
    float[] tabStops
)
public function SetTabStops (
    firstTabOffset : float, 
    tabStops : float[]
)

Parameter

  • firstTabOffset
    Die Anzahl von Leerzeichen zwischen dem Anfang einer Textzeile und dem ersten Tabstopp.
  • tabStops
    Ein Array von Abständen zwischen Tabstopps in den von der Graphics.PageUnit-Eigenschaft angegebenen Einheiten.

Hinweise

Jeder Tabstoppoffset im tabStops-Array mit Ausnahme des ersten ist relativ zum vorhergehenden. Der erste Tabstoppoffset ist zur ursprünglichen von firstTabOffset angegebenen Offsetposition relativ. Wenn beispielsweise die Anfangsoffsetposition 8 und der erste Tabstoppoffset 50 ist, dann befindet sich der erste Tabstopp auf Position 58. Wenn die Anfangsoffsetposition 0 (null) ist, dann bezieht sich der erste Tabstoppoffset auf Position 0 (null), dem Ursprung der Zeichenfolge.

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:

  • Legt die Tabstopps des StringFormat fest.

  • Zeichnet die Zeichenfolge und das Layoutrechteck. Beachten Sie, dass die Zeichenfolge Tabstopps enthält. Die Tabstoppeinstellungen des StringFormat geben die Offsets des Textes an, der Tabstopps enthält.

  • Ruft die Tabstopps ab und verwendet oder überprüft die Werte.

Public Sub GetSetTabStopsExample2(ByVal e As PaintEventArgs)
    Dim g As Graphics = e.Graphics

    ' Tools used for drawing, painting.
    Dim redPen As New Pen(Color.FromArgb(255, 255, 0, 0))
    Dim blueBrush As New SolidBrush(Color.FromArgb(255, 0, 0, 255))

    ' Layout and format for text.
    Dim myFont As New Font("Times New Roman", 12)
    Dim myStringFormat As New StringFormat
    Dim enclosingRectangle As New Rectangle(20, 20, 500, 100)
    Dim tabStops As Single() = {150.0F, 100.0F, 100.0F}

    ' Text with tabbed columns.
    Dim myString As String = "Name" & ControlChars.Tab & "Tab 1" _
    & ControlChars.Tab & "Tab 2" & ControlChars.Tab & "Tab 3" _
    & ControlChars.Cr & "George Brown" & ControlChars.Tab & "One" _
    & ControlChars.Tab & "Two" & ControlChars.Tab & "Three"

    ' Set the tab stops, paint the text specified by myString,
    ' and draw rectangle that encloses the text.
    myStringFormat.SetTabStops(0.0F, tabStops)
    g.DrawString(myString, myFont, blueBrush, _
    RectangleF.op_Implicit(enclosingRectangle), myStringFormat)
    g.DrawRectangle(redPen, enclosingRectangle)

    ' Get the tab stops.
    Dim firstTabOffset As Single
    Dim tabStopsObtained As Single() = _
    myStringFormat.GetTabStops(firstTabOffset)
    Dim j As Integer
    For j = 0 To tabStopsObtained.Length - 1

        ' Inspect or use the value in tabStopsObtained[j].
        Console.WriteLine(ControlChars.Cr & "  Tab stop {0} = {1}", _
        j, tabStopsObtained(j))
    Next j
End Sub
public void GetSetTabStopsExample2(PaintEventArgs e)
{
    Graphics     g = e.Graphics;
             
    // Tools used for drawing, painting.
    Pen          redPen = new Pen(Color.FromArgb(255, 255, 0, 0));
    SolidBrush   blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255));
             
    // Layout and format for text.
    Font         myFont = new Font("Times New Roman", 12);
    StringFormat myStringFormat = new StringFormat();
    Rectangle    enclosingRectangle = new Rectangle(20, 20, 500, 100);
    float[]      tabStops = {150.0f, 100.0f, 100.0f};
             
    // Text with tabbed columns.
    string       myString =
        "Name\tTab 1\tTab 2\tTab 3\nGeorge Brown\tOne\tTwo\tThree";
             
    // Set the tab stops, paint the text specified by myString, draw the
    // rectangle that encloses the text.
    myStringFormat.SetTabStops(0.0f, tabStops);
    g.DrawString(myString, myFont, blueBrush,
        enclosingRectangle, myStringFormat);
    g.DrawRectangle(redPen, enclosingRectangle);
             
    // Get the tab stops.
    float   firstTabOffset;
    float[] tabStopsObtained = myStringFormat.GetTabStops(out firstTabOffset);
    for(int j = 0; j < tabStopsObtained.Length; j++)
    {
             
        // Inspect or use the value in tabStopsObtained[j].
        Console.WriteLine("\n  Tab stop {0} = {1}", j, tabStopsObtained[j]);
    }
}
void GetSetTabStopsExample2( PaintEventArgs^ e )
{
   Graphics^ g = e->Graphics;

   // Tools used for drawing, painting.
   Pen^ redPen = gcnew Pen( Color::FromArgb( 255, 255, 0, 0 ) );
   SolidBrush^ blueBrush = gcnew SolidBrush( Color::FromArgb( 255, 0, 0, 255 ) );

   // Layout and format for text.
   System::Drawing::Font^ myFont = gcnew System::Drawing::Font( "Times New Roman",12 );
   StringFormat^ myStringFormat = gcnew StringFormat;
   Rectangle enclosingRectangle = Rectangle(20,20,500,100);
   array<Single>^tabStops = {150.0f,100.0f,100.0f};

   // Text with tabbed columns.
   String^ myString = "Name\tTab 1\tTab 2\tTab 3\nGeorge Brown\tOne\tTwo\tThree";

   // Set the tab stops, paint the text specified by myString, draw the
   // rectangle that encloses the text.
   myStringFormat->SetTabStops( 0.0f, tabStops );
   g->DrawString( myString, myFont, blueBrush, enclosingRectangle, myStringFormat );
   g->DrawRectangle( redPen, enclosingRectangle );

   // Get the tab stops.
   float firstTabOffset;
   array<Single>^tabStopsObtained = myStringFormat->GetTabStops( firstTabOffset );
   for ( int j = 0; j < tabStopsObtained->Length; j++ )
   {
      // Inspect or use the value in tabStopsObtained[j].
      Console::WriteLine( "\n  Tab stop {0} = {1}", j, tabStopsObtained[ j ] );
   }
}
public void GetSetTabStopsExample2(PaintEventArgs e)
{
    Graphics g = e.get_Graphics();

    // Tools used for drawing, painting.
    Pen redPen = new Pen(Color.FromArgb(255, 255, 0, 0));
    SolidBrush blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255));

    // Layout and format for text.
    Font myFont = new Font("Times New Roman", 12);
    StringFormat myStringFormat = new StringFormat();
    Rectangle enclosingRectangle = new Rectangle(20, 20, 500, 100);
    float tabStops[] =  { 150, 100, 100 };

    // Text with tabbed columns.
    String myString = "Name\tTab 1\tTab 2\tTab 3\nGeorge Brown\tOne\tTwo" 
                    + "\tThree";

    // Set the tab stops, paint the text specified by myString, draw the
    // rectangle that encloses the text.
    myStringFormat.SetTabStops(0, tabStops);
    g.DrawString(myString, myFont, blueBrush, 
        RectangleF.op_Implicit(enclosingRectangle), myStringFormat);
    g.DrawRectangle(redPen, enclosingRectangle);

    // Get the tab stops.
    float firstTabOffset = 0.0F;
    float tabStopsObtained[] = myStringFormat.GetTabStops(firstTabOffset);

    for (int j = 0; j < tabStopsObtained.length; j++) {
        // Inspect or use the value in tabStopsObtained[j].
        Console.WriteLine("\n  Tab stop {0} = {1}", 
            System.Convert.ToString(j), 
            System.Convert.ToString(tabStopsObtained.get_Item(j)));
    }
} //GetSetTabStopsExample2

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

Siehe auch

Referenz

StringFormat-Klasse
StringFormat-Member
System.Drawing-Namespace