MaterialSkin icon indicating copy to clipboard operation
MaterialSkin copied to clipboard

Making MaterialSkin DPI-Aware

Open Cale-Torino opened this issue 4 years ago • 4 comments

Hi guys. Recently I have been working on improving the DPI awareness of some WinForms applications. As you can see below using a 4K screen can mess the form up badly..

DPI_PROB

However there is a few fixes.

1.

For .NET Framework 4.6.1

In the Program.cs file add the code below to the static void Main() method :

            // DPI-Aware Application
            if (Environment.OSVersion.Version.Major >= 6)
            { 
               SetProcessDPIAware();
            }

After adding the if statement add the DLL to import below the static void Main() method:

        // DPI-Aware Application dllimport
        [DllImport("user32.dll")]
        private static extern bool SetProcessDPIAware();

Example:

Screenshot 2021-02-18 112447

Finally change the AutoScaleMode from Font to DPI and then your app should look like below:

DPI_PROBB

2.

For .NET Framework 4.7.2

In your WinForms App.config file paste this:

<System.Windows.Forms.ApplicationConfigurationSection>
    <add key="DpiAwareness" value="PerMonitorV2" />
</System.Windows.Forms.ApplicationConfigurationSection>

Then create a app.manifest file and paste or comment in this line:

<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />

After doing the above I was able to get great DPI results on my 4k screens.

Check out this and this for more information.

N.B

Although this helps there are still a few annoyances like the form buttons in the top right hand corner are very small. Also the materialTextBox cursor does not display next to the text... it looks as if there is white spaces but there is not.

If anyone has a better solution please share it here. Hope this helps.

Cale-Torino avatar Feb 18 '21 10:02 Cale-Torino

Thank you so much!

leocb avatar Feb 18 '21 12:02 leocb

Upon Reviewing this fix, while it does fix the blurriness of the app, a lot of other code needs to be changed if I want to support this correctly in the lib, mainly the padding and font sizes needs to be changed, currently they are hard coded inside the components, also, the drawer will "revert" back to the same size as 100% scaling and Icons are misaligned. I can only wish it was this easy to fix everything haha.

If anyone want to apply this to their own project, feel free, this setting is independent from the lib. Be warned: bugs await you!

leocb avatar Feb 22 '21 03:02 leocb

also related to #93

leocb avatar Feb 22 '21 03:02 leocb

Thanks :) happy to help

Cale-Torino avatar Feb 22 '21 15:02 Cale-Torino