MaterialSkin
MaterialSkin copied to clipboard
Making MaterialSkin DPI-Aware
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..
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:
Finally change the AutoScaleMode
from Font
to DPI
and then your app should look like below:
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.
Thank you so much!
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!
also related to #93
Thanks :) happy to help