The EASY way to make a C# Windows.forms app really per monitor DPI aware

As posted in another post, many apps have problems with windows scaling.

See these screen-dumps from Windows lengthy guide that was found here

Here is a reasonably minimalistic approach. You will often just need code like this:


    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            DPI_Per_Monitor.TryEnableDPIAware();
        }

        void SetUserFonts(float scaleFactorX, float scaleFactorY) {
            Font = new Font(Font.FontFamily, 11f * scaleFactorX, GraphicsUnit.Pixel);
        }
        protected override void DefWndProc(ref Message m) {
            DPI_Per_Monitor.Check_WM_DPICHANGED(SetUserFonts,m);
            base.DefWndProc(ref m);
        }

    }

You will need to obey a few rules, but often it can be implemented in existing code in minutes!

Continue reading “The EASY way to make a C# Windows.forms app really per monitor DPI aware”

Save and restore positions of windows, WindowsPosSaveNRestore

WindowsPosSaveNRestore is a tool to save the position of windows for later restore

This is primarily useful if you frequently change display configuration, say add/remove external monitor(s) e.g. by docking, or turning a device with autorotate active.

Windows also has the bug that it sometimes cram all open windows (and icons [+]) on the primary screen on sleep.

Continue reading “Save and restore positions of windows, WindowsPosSaveNRestore”