次の方法で共有


StringFormat.GetTabStops メソッド

この StringFormat オブジェクトのタブ ストップを取得します。

Public Function GetTabStops( _
   <Out()> ByRef firstTabOffset As Single _) As Single()
[C#]
public float[] GetTabStops(   out floatfirstTabOffset);
[C++]
public: float GetTabStops(   [   Out] float* firstTabOffset)  __gc[];
[JScript]
public function GetTabStops(
   firstTabOffset : float) : float[];

パラメータ

  • firstTabOffset
    テキスト行の先頭と最初のタブ ストップ間の空白の数。

戻り値

タブ ストップの間隔 (空白の数) の配列。

使用例

[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。

  • StringFormat のタブ ストップを設定します。
  • 文字列とレイアウト四角形を描画します。この文字列にはタブが含まれます。 StringFormat のタブ設定によって、タブ付きテキストのオフセットが指定されます。
  • タブ ストップを取得し、その値を使用または検査します。
 
Public Sub GetSetTabStopsExample(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() =  {150F, 100F, 100F}
' 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,the
'  and draw rectangle that encloses the text.
myStringFormat.SetTabStops(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
        
[C#] 
public void GetSetTabStopsExample(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, and 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]);
}
}
        

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

StringFormat クラス | StringFormat メンバ | System.Drawing 名前空間