【发布时间】:2012-03-27 19:38:46
【问题描述】:
请看我的代码:
Graphics grfx = Graphics.FromImage(new Bitmap(1, 1));
System.Drawing.Font f = new System.Drawing.Font("Times New Roman", 10, FontStyle.Regular);
const string text1 = "check_space";
SizeF bounds1 = grfx.MeasureString(text1, f);
const string text2 = "check_space ";
SizeF bounds2 = grfx.MeasureString(text2, f);
Assert.IsTrue(bounds1.Width < bounds2.Width); // I have Fail here!
我想知道为什么我的测试失败了。为什么文本with尾部空格不比文本没有空格宽?
更新:我可以理解这两个字符串不相等。但据我所知,字符串 with 空间的宽度应大于字符串 without 空间。不要?
【问题讨论】:
-
他们是平等的吗?
-
试试
"check_space."和"check_space ."。它们不相等。 -
我已经在下面发布了答案。我不知道你为什么不接受它......
-
因为它必须经过一段时间-系统不允许立即接受它
标签: c# graphics measurement