本文整理汇总了C#中System.Drawing.StringFormat.SetTabStops方法的典型用法代码示例。如果您正苦于以下问题:C# StringFormat.SetTabStops方法的具体用法?C# StringFormat.SetTabStops怎么用?C# StringFormat.SetTabStops使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.StringFormat
的用法示例。
在下文中一共展示了StringFormat.SetTabStops方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSetTabStopsExample2
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]);
}
}
示例2: Form1
//引入命名空间
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Imaging;
public class Form1 : System.Windows.Forms.Form
{
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Text = "";
this.Resize += new System.EventHandler(this.Form1_Resize);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, this.ClientRectangle);
Font f = new Font("Times New Roman", 12);
Font bf = new Font(f, FontStyle.Bold);
StringFormat sf = new StringFormat();
float[] ts = { 10.0f, 70.0f, 100.0f, 90.0f };
sf.SetTabStops(0.0f, ts);
// The \t escape-sequence in these lines specifies the tab
string s1 = "\tName\tEye Color\tHeight";
string s2 = "\tBob\tBrown\t175cm";
string s3 = "\tMary\tBlond\t161cm\n\tBill\tBlack\t168cm";
g.DrawString(s1, bf, Brushes.Black, 20, 20, sf);
g.DrawString(s2, f, Brushes.Blue, 20, 20 + bf.Height, sf);
g.DrawString(s3, f, Brushes.Blue, 20,
20 + bf.Height + f.Height, sf);
f.Dispose();
bf.Dispose();
}
private void Form1_Resize(object sender, System.EventArgs e)
{
Invalidate();
}
}