Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DpiAware: problem with ControlBox #97

Open
KamilSzymborski opened this issue Jul 8, 2019 · 17 comments
Open

DpiAware: problem with ControlBox #97

KamilSzymborski opened this issue Jul 8, 2019 · 17 comments

Comments

@KamilSzymborski
Copy link

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
Copy link
Owner

Is this a suggested fix?

@KamilSzymborski
Copy link
Author

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
Copy link
Author

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

@KamilSzymborski
Copy link
Author

I don't know how to fix it.

@KamilSzymborski
Copy link
Author

KamilSzymborski commented Sep 6, 2019

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

I have 13" inch notebook with FHD.

mb.

@dennismagno
Copy link
Owner

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

@KamilSzymborski
Copy link
Author

Good luck!

@ghost
Copy link

ghost commented Sep 21, 2019

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
Copy link
Author

KamilSzymborski commented Sep 22, 2019

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

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

Untitled

@ghost
Copy link

ghost commented Sep 23, 2019

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link

@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
Copy link
Author

KamilSzymborski commented Feb 20, 2021

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
Copy link

aceofspades0494 commented Feb 28, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants