Why am I getting an error on this line?
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 toMeasure
:
string toMeasure = data[e.Index].Substring(0, keywords - 1);
Error in line:
float startPos = e.Graphics.MeasureString(toMeasure, f);
Mistake:
Cannot implicitly convert type 'System.Drawing.SizeF' to 'float'
How can I fix this? As the second line needs to be floating, but the first line cannot convert from SizeF
to float
.
source to share
The method MeasureString
returns an object SizeF
.
SizeF startPos = e.Graphics.MeasureString(toMeasure, f);
source to share
As the error says, the MeasureString function returns System.Drawing.SizeF
which is ordered pair of floating-point numbers
.
source to share