GetCharABCWidths or GetCharABCWidthsFloat analogs in .NET

  • Thread starter Thread starter Alexander Smirnov
  • Start date Start date
A

Alexander Smirnov

What methods of what classes I must use in .NET to get the info that
GetCharABCWidthsFloat gives?
Or what is a way to obtain char widths for the font in .NET ?

Thanks in advance.
 
Alexander said:
What methods of what classes I must use in .NET to get the info that
GetCharABCWidthsFloat gives?
Or what is a way to obtain char widths for the font in .NET ?

Thanks in advance.

Hi Alex,

You can obtain the char width by MeasureString(...):
Font font = new Font("Courier New", 12, GraphicsUnit.Pixel);
float width = font.Size;
Graphics g = this.CreateGraphics();
width = g.MeasureString("A", font).Width;
g.Dispose();

Or just call GetCharABCWidthsFloat:

[DllImport("gdi32", EntryPoint="GetCharABCWidthsFloat")]
public static extern int GetCharABCWidthsFloatA(int hDC, int iFirstChar,
int iLastChar, ref ABCFLOAT lpABCF)

HTH,
Petar Atanasov
http://a-wake.net
 
Alexander said:
What methods of what classes I must use in .NET to get the info that
GetCharABCWidthsFloat gives?
Or what is a way to obtain char widths for the font in .NET ?

I'm not aware of a .NET method that is exactly like
GetCharABCWidthsFloat. So Peter's suggestion to use p/invoke to simply
use the unmanaged method may be the most appropriate solution.

If you choose to use the Graphics class instead (which I think would be
fine as well), you may find the Graphics.MeasureCharacterRanges() method
more appropriate that Graphics.MeasureString() as was suggested. With
the former, you can create your own string representing the range of
characters you want, and then get all the widths in a single call rather
than calling MeasureString() repeatedly.

Pete
 
Back
Top