StringFormat.GetTabStops(Single) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取此 StringFormat 对象的制表位。
public:
cli::array <float> ^ GetTabStops([Runtime::InteropServices::Out] float % firstTabOffset);
public float[] GetTabStops (out float firstTabOffset);
member this.GetTabStops : single -> single[]
Public Function GetTabStops (ByRef firstTabOffset As Single) As Single()
参数
- firstTabOffset
- Single
文本行开头和第一个制表位之间的空格数。
返回
Single[]
制表位之间的距离数组(以空格数为单位)。
示例
下面的示例设计用于 Windows 窗体,它需要 PaintEventArgse
,这是 Paint 事件处理程序的参数。 该代码执行以下操作:
设置 StringFormat的制表位。
绘制字符串和布局矩形。 请注意,字符串包含选项卡。 StringFormat 的选项卡设置指定制表符文本的偏移量。
获取制表位并使用或检查值。
public:
void GetSetTabStopsExample1( 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, 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;
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 GetSetTabStopsExample1(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]);
}
}
Public Sub GetSetTabStopsExample1(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,the
' 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