GDI+ 绘制自定义制表位位数的文本。
先上图;
2,使用
StringFormat中的SetTabStops来设置制表位所占的空间
StringFormat sf = new StringFormat();
sf.StTabStops(5f, ff);
sf.StTabStops(5f, ff);
代码如下:
View Code
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Font f = new Font("Aries", 15, FontStyle.Italic);
Font fb = new Font(f, FontStyle.Bold);
string s1 = "\twtq\twwttqq\twwwtttqqq\twwwtttttqqqqq";
string s2="\twwwww\trerere\tfdfdfdfd\tfdfdfdfd";
float[] ff = new float[]{100f,90f,200f,15f};
StringFormat sf = new StringFormat();
sf.SetTabStops(5f, ff);
g.DrawString(s1, f, Brushes.Red, 0f, 20f,sf);
g.DrawString(s1, fb, Brushes.Red, 0f, 100f, sf);
}
{
Graphics g = e.Graphics;
Font f = new Font("Aries", 15, FontStyle.Italic);
Font fb = new Font(f, FontStyle.Bold);
string s1 = "\twtq\twwttqq\twwwtttqqq\twwwtttttqqqqq";
string s2="\twwwww\trerere\tfdfdfdfd\tfdfdfdfd";
float[] ff = new float[]{100f,90f,200f,15f};
StringFormat sf = new StringFormat();
sf.SetTabStops(5f, ff);
g.DrawString(s1, f, Brushes.Red, 0f, 20f,sf);
g.DrawString(s1, fb, Brushes.Red, 0f, 100f, sf);
}
说明:以上代码通过定义float[]来统计每个制表符相对于前一个制表符所占的位数