Oliver Bock
Oliver Bock

Reputation: 5105

How can I avoid exceptions in Graphics.MeasureString() with bad zero width joiner?

When I call Graphics.MeasureString("?\u200d") I get an ExternalException "A generic error occurred in GDI+".

\u200d is the unicode "zero width joiner", and I guess it is being used incorrectly, but I cannot control the data my users supply, and yet I want to measure it for display. It also throws the exception when it draws.

I guess I just have to work around this, though it surprises me.

I note that Visual Studio can render the string, perhaps because it is not built on top of GDI+?

Any suggestions?

Upvotes: 2

Views: 285

Answers (1)

Oliver Bock
Oliver Bock

Reputation: 5105

Use TextRenderer.MeasureText(), and see the excellent (long) answer in Graphics.DrawString vs TextRenderer.DrawText?Which can Deliver Better Quality

Upvotes: 2

Related Questions