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?
You can try this hack: Apply the transform to the font size you're using to measure: Drawing with a 12pt font on 120dpi will take the same number of pixels as Drawing with 12*120/96=15 on a 96 dpi.