I have a C# WinForms application which consists of server and client side. I use TextRenderer.MeasureText(string text, Font font)
method to measure text.
At some moment I need to measure text on server side, as if it was on client. I send Graphics.DpiX and Graphics.DpiY values from client to server. Based on that values, how can I measure text on server side? The key point is that client and server Dpi might be different.
I guess, I can create Graphics
object from Dpi values somehow and use TextRenderer.MeasureText(IDeviceContext dc, string text, Font font)
overload to measure my text. But how to create Graphics
from just DpiX and DpiY values?
MeasureString(string text, Font font)
method ofGraphics
object returns correct value then, butTextRenderer
doesn't seem to takeGraphics.DpiX
andGraphics.DpiY
values into account. Any idea, why could that happen? I wouldn't like to useGraphics.MeasureString(string text, Font font)
method, as I know it might be inaccurate. – JeffcottGraphics.MeasureString(string text, Font font)
? Is that too bad? – JeffcottTextFormatFlags.PreserveGraphicsTranslateTransform
? – Futile