Search code examples
c#hidpi

Windows scale is affecting my application font


I'm having an issue on my program when i run it with scale 100% in windows settings the application looks good as i design it. But when the scale is set for example to 125%. I got a problem with graphics the font became more big.

I build different binaries with different AutoscaleMode value (None, Font and DPI). Then, I launch them with scale 100% and 120% (each time i log off to get the scale applied).

enter image description here

Here is the screenshots of different cases (in the textbox i writed the scale that is used): enter image description here

I'm using MetroFramework for components.
Sourcecode is available here (the last commit).
How can fix my application to look the same in different scale windows setting?


Solution

  • I used SetProcessDPIAware and it fixed the issue and now the application works on different scale modes and there is only an issue with combobox size that change. I found already a ticket opened on git here for the combobox.

    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            SetProcessDPIAware();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool SetProcessDPIAware();
    }