dennismagno / metroframework-modern-ui

My humble attempt to bring the new Modern UI alias Metro UI of Windows 8 to .NET Windows Forms applications.
http://dennismagno.github.io/metroframework-modern-ui
Other
861 stars 1.08k forks source link

DpiAware: problem with ControlBox #97

Open KamilSzymborski opened 4 years ago

KamilSzymborski commented 4 years ago

https://ibb.co/gVbzkkr

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();
    }
dennismagno commented 4 years ago

Is this a suggested fix?

KamilSzymborski commented 4 years ago

I know why you ask - I forgot to mention something: the problem occurs when the interface scaling in the system is greater than 100% - then the application scales.

KamilSzymborski commented 4 years ago

SetProcessDpiAware is the same as right click -> properties -> compatibility -> change high DPI settings -> high DPI scalling override: application on exe, or link.

KamilSzymborski commented 4 years ago

I don't know how to fix it.

KamilSzymborski commented 4 years ago

Oh sorry, NOT ALWAYS, in my case it occurs when scaling 150%.

I have 13" inch notebook with FHD.

mb.

dennismagno commented 4 years ago

Ok let try to replicate the issue based on the information that you provided. Thanks a lot for your findings.

KamilSzymborski commented 4 years ago

Good luck!

ghost commented 4 years ago

within your project select Add new file and add a "application manifest", add the following in the manifest file:

add-inside-app-manifest-file.zip

Then open your project properties, select application tab then go to the manifest section, select your newly created manifest file, close property window and rebuild solution - should fix your problem.

KamilSzymborski commented 4 years ago

Still the same at 150% on 13" on Full HD.

This is just one of the ways to enable dpi aware.

Untitled

ghost commented 4 years ago

Hi, within the manifest file inside assembly identity node is that the name of your application? if not input the name of your app.exe.

Try - within form properties select "AutoScaleMode" change from "Font" to "DPI" see if this helps.

failing that, i'll code up a sample app for all different dpi and upload it here - give me a day or so.

KamilSzymborski commented 4 years ago

Hi, within the manifest file inside assembly identity node is that the name of your application? if not input the name of your app.exe.

Corrected. However, everything worked fine, the application without scaling on my device looks terrible and you can't miss it.

Try - within form properties select "AutoScaleMode" change from "Font" to "DPI" see if this helps.

I tried.

failing that, i'll code up a sample app for all different dpi and upload it here - give me a day or so.

I know how to write applications that scale well.

I generally don't use MetroForm because I don't like - I only use components from MetroFramework.

I just wanted to report a bug.

But I appreciate the willingness.

:)

KamilSzymborski commented 4 years ago

I fixed it.

Original: newButton.Size = new Size(25, 20); To (x and y +4): newButton.Size = new Size(29, 24);

Untitled

There was simply no space for text on the button.

KamilSzymborski commented 4 years ago

It's a solution for my 13-inch Full HD laptop. But it will probably be bad again with 12-inch Full HD etc. Maybe you need to provide a picture instead of button text.

KamilSzymborski commented 4 years ago

And it would be good to add scaling options to MetroForm.

if (Environment.OSVersion.Version.Major >= 6) SetProcessDPIAware();
[DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
aceofspades0494 commented 3 years ago

@KamilSzymborski I still do not understand how you were able to fix the maximize and minimize boxes in the Control Box using DPI Aware. Could you elaborate on how you fixed that?

KamilSzymborski commented 3 years ago

Finally I solved this by implementing auto-scaling to the window buttons.

float dpi;

using (var g = newButton.CreateGraphics())
    // 96 is base /default DPI, is like 100% system scaling
    dpi = (96 / Math.Max(g.DpiX, g.DpiY)); 

var oldButtonSize = newButton.Size;

var newButtonWidth = Convert.ToInt32(oldButtonSize.Width + (oldButtonSize.Width * dpi));
var newButtonHeight = Convert.ToInt32(oldButtonSize.Height + (oldButtonSize.Height * dpi));

newButton.Size = new Size(newButtonWidth, newButtonHeight);

I am sending you MetroForm.cs - replace it in MetroFramework/Forms.

MetroForm.zip

aceofspades0494 commented 3 years ago

Kamil,

Thank you very much!!! I can't express my gratitude enough, this really helped with the issue I was dealing with.

On Sat, Feb 20, 2021 at 12:02 AM Kamil Szymborski notifications@github.com wrote:

Finally I solved this by implementing auto-scaling to the window buttons.

float dpi; using (var g = newButton.CreateGraphics()) dpi = (96 / Math.Max(g.DpiX, g.DpiY)); var oldButtonSize = newButton.Size; var newButtonWidth = Convert.ToInt32(oldButtonSize.Width + (oldButtonSize.Width dpi));var newButtonHeight = Convert.ToInt32(oldButtonSize.Height + (oldButtonSize.Height dpi)); newButton.Size = new Size(newButtonWidth, newButtonHeight);

I am sending you MetroForm.cs - replace it in MetroFramework/Forms.

MetroForm.zip https://github.com/dennismagno/metroframework-modern-ui/files/6014224/MetroForm.zip

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dennismagno/metroframework-modern-ui/issues/97#issuecomment-782567770, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFC3CJGHV2JHUGPQLZ6KRCTS75F7XANCNFSM4H66BC7A .