Lets say I render the character “A” to the screen with a size 14 font in Arial Regular. Is there a way in C# to calculate how many pixels wide it is?
The way I’m rendering text is through ESRI’s ArcEngine which makes calls to GDI or GDI+ (I don’t know which) in a round about fashion via the DynamicDisplay engine.
It depends on the rendering engine being used. .NET may use GDI or GDI+. Switching can be done by setting the
UseCompatibleTextRenderingproperty accordingly or calling theApplication.SetCompatibleTextRenderingDefaultmethod.When using GDI+ you should use
MeasureString:When using GDI (i.e. the native Win32 rendering) you should use the
TextRendererclass:More details are described in this article:
Note that the above talks about Windows Forms. In WPF you would be using
FormattedText