4
float startPos = e.Graphics.MeasureString(toMeasure, f);
                    e.Graphics.DrawString(keyword, f, sb, new PointF(e.Bounds.X + (int)startPos, e.Bounds.Y));

这是f

using (Font f = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular))

这是toMeasure

string toMeasure = data[e.Index].Substring(0, keywords - 1);

错误在线:

float startPos = e.Graphics.MeasureString(toMeasure, f);

错误是:

无法将类型“System.Drawing.SizeF”隐式转换为“float”

我该如何解决?由于第二行应该浮动,但第一行不能从转换SizeFfloat.

4

3 回答 3

6

如果你想要的Widthstring将不得不WidthSizeF返回的结构中获得MeasureString

例子:

float startPos = e.Graphics.MeasureString(toMeasure, f).Width;
于 2013-02-18T02:22:17.400 回答
2

方法MeasureString返回SizeF对象。

SizeF startPos = e.Graphics.MeasureString(toMeasure, f);
于 2013-02-18T02:19:40.827 回答
0

正如错误所说,MeasureString函数返回 a System.Drawing.SizeF,即 a ordered pair of floating-point numbers

于 2013-02-18T02:20:18.083 回答