日期:2014-05-18  浏览次数:20960 次

DrawString描画不出空格的下划线
描画一个文字,如" 文 字 ",要求带有下划线,但是描画的结果只是" 文 字",而且有下划线,后面的空格没有了,也没有下划线。代码如下:
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
//确定字体
Font font= new Font("宋体",20,FontStyle.Underline,GraphicsUnit.Point);

//确定文字格式
StringFormat strFormat = new StringFormat();
strFormat.Alignment = StringAlignment.Near;
strFormat.Trimming = StringTrimming.EllipsisWord;

//文字描画颜色
SolidBrush brush = new SolidBrush(Color.Black);
//描画普通文字组
e.Graphics.DrawString(" 文 字 ",font,brush,new Point(100,100),strFormat);

brush.Dispose();
}

------解决方案--------------------
怪. 

按照下面的方式,效果和划上线一样. 位置和线的宽度相同。

(1)字体用 "" (不太清楚是用的哪种字体)
(2)结尾处 加一下划线 _ 如:“ 文 字  _”

C# code

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
    //确定字体 
    Font font = new Font("", 20, FontStyle.Underline, GraphicsUnit.Point);

    //确定文字格式 
    StringFormat strFormat = new StringFormat();
    strFormat.Alignment = StringAlignment.Center;
    strFormat.Trimming = StringTrimming.EllipsisWord;

    //文字描画颜色 
    SolidBrush brush = new SolidBrush(Color.Black);
    //描画普通文字组 
    e.Graphics.DrawString("    文  字  _", font, brush, new Point(100, 100), strFormat);

    brush.Dispose();
}

------解决方案--------------------
探讨
怪.

按照下面的方式,效果和划上线一样. 位置和线的宽度相同。

(1)字体用 ""  (不太清楚是用的哪种字体)
(2)结尾处 加一下划线 _  如:“    文  字  _”

C# codeprivatevoid Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{//确定字体 Font font=new Font("",20, FontStyle.Underline, GraphicsUnit.Point);//确定文字格式 StringFormat strFormat=new StringFormat();
strFormat.Alignment= StringAlignment.Center;
strFormat.Trimming= StringTrimming.EllipsisWord;//文字描画颜色 SolidBrush brush=new SolidBrush(Color.Black);//描画普通文字组 e.Graphics.DrawString(" 文 字  _", font, brush,new Point(100,100), strFormat);

brush.Dispose();
}