StringFormat.SetTabStops(Single, Single[]) 메서드

정의

StringFormat 개체의 탭 정지를 설정합니다.

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

텍스트 줄의 시작과 첫 번째 탭 정지 사이의 공백 수입니다.

tabStops
Single[]

탭 정지 사이의 거리가 PageUnit 속성에 지정된 단위로 들어 있는 배열입니다.

예제

다음 예제는 Windows Forms 사용하도록 설계되었으며 이벤트 처리기의 Paint 매개 변수인 가 필요합니다.PaintEventArgse 코드는 다음 작업을 수행합니다.

  • 의 탭 정지를 StringFormat설정합니다.

  • 문자열 및 레이아웃 사각형을 그립니다. 문자열에는 탭이 포함되어 있습니다. 의 StringFormat 탭 설정은 탭 텍스트의 오프셋을 지정합니다.

  • 탭 중지를 가져오고 값을 사용하거나 검사합니다.

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 각 탭 중지 오프셋은 이전 오프셋과 상대적입니다. 첫 번째 탭 중지 오프셋은 에 지정된 firstTabOffset초기 오프셋 위치를 기준으로 합니다. 예를 들어 초기 오프셋 위치가 8이고 첫 번째 탭 중지 오프셋이 50인 경우 첫 번째 탭 중지 위치는 58입니다. 초기 오프셋 위치가 0이면 첫 번째 탭 중지 오프셋은 문자열 원점인 위치 0을 기준으로 합니다.

적용 대상