Reputation: 471
float startPos = e.Graphics.MeasureString(toMeasure, f);
e.Graphics.DrawString(keyword, f, sb, new PointF(e.Bounds.X + (int)startPos, e.Bounds.Y));
This is f
:
using (Font f = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular))
And this is toMeasure
:
string toMeasure = data[e.Index].Substring(0, keywords - 1);
The error is on the line:
float startPos = e.Graphics.MeasureString(toMeasure, f);
The error is:
Cannot implicitly convert type 'System.Drawing.SizeF' to 'float'
How can I fix it? Since the second line should get float but the first line can't convert from SizeF
to float
.
Upvotes: 4
Views: 807
Reputation: 43636
If you want the Width
of the string
you will have to get the Width
from the SizeF
stucture returned from MeasureString
Example:
float startPos = e.Graphics.MeasureString(toMeasure, f).Width;
Upvotes: 6
Reputation: 31972
As the error says, the MeasureString function returns a System.Drawing.SizeF
, which is an ordered pair of floating-point numbers
.
Upvotes: 0
Reputation: 56222
Method MeasureString
returns SizeF
object.
SizeF startPos = e.Graphics.MeasureString(toMeasure, f);
Upvotes: 2