StringFormat.SetTabStops(Single, Single[]) メソッド

定義

この StringFormat オブジェクトのタブ ストップを設定します。Sets tab stops for this StringFormat object.

public:
 void SetTabStops(float firstTabOffset, cli::array <float> ^ tabStops);
public void SetTabStops (float firstTabOffset, float[] tabStops);
member this.SetTabStops : single * single[] -> unit
Public Sub SetTabStops (firstTabOffset As Single, tabStops As Single())

パラメーター

firstTabOffset
Single

テキスト行の先頭と最初のタブ ストップ間の空白の数。The number of spaces between the beginning of a line of text and the first tab stop.

tabStops
Single[]

タブ ストップの間隔の配列。単位は、PageUnit プロパティによって指定します。An array of distances between tab stops in the units specified by the PageUnit property.

次の例は、Windows フォームで使用するように設計さPaintEventArgsれています。これはPaint 、イベントハンドラーのパラメーターであるを必要eとします。The following example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. コードは、次のアクションを実行します。The code performs the following actions:

  • のタブストップを設定しStringFormatます。Sets the tab stops of the StringFormat.

  • 文字列とレイアウト四角形を描画します。Draws the string and the layout rectangle. 文字列にタブが含まれていることに注意してください。Note that the string contains tabs. のタブ設定は、 StringFormatタブ付きテキストのオフセットを指定します。The tab settings of the StringFormat specify the offsets of the tabbed text.

  • タブストップを取得し、値を使用または検査します。Gets the tab stops and uses or inspects the values.

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.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]);
    }
}
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

注釈

最初のタブを除く、 tabStops配列内の各タブストップのオフセットは、前の位置からの相対値です。Each tab-stop offset in the tabStops array, except the first one, is relative to the previous one. 最初のタブストップのオフセットは、によってfirstTabOffset指定された最初のオフセット位置に対する相対値です。The first tab-stop offset is relative to the initial offset position specified by firstTabOffset. たとえば、最初のオフセット位置が8で、1番目のタブストップのオフセットが50の場合、最初のタブストップは位置58になります。For example, if the initial offset position is 8 and the first tab-stop offset is 50, then the first tab stop is at position 58. 最初のオフセット位置が0の場合、最初のタブストップのオフセットは、文字列の原点である位置0に対して相対的になります。If the initial offset position is zero, then the first tab-stop offset is relative to position 0, the string origin.

適用対象