Search code examples
c#gdi+dpidrawstring

Windows DPI setting affects Graphics.DrawString


I have created a new Bitmap object and now want do draw some text to it using GDI+. So I call Graphics.DrawString(...).

The problem is that the size of the string depends on Windows 7's DPI settings. Is there any way to make my text drawing independent of the windows settings?

PS: The DPI settings seem to affect text only. A rect for example stys the same size when changing the DPI...


Solution

  • Just found the solution myself: The key is to create the font with the parameter GraphicsUnit.Pixel. That way drawing strings gets independent from the system's DPI settings.