locked
Need to know how to pinvoke the SetProcessDPIAwareness() function RRS feed

Answers

  • Hi Sansoft

    I think the best idea is to apply the DPI aware setting then make the application look OK.

    If you don't do this then it will look bad when moved to another device that is very different.

    Hopefully if you set DPI awareness and then move it to another machine it will look approximately the same.

    • Proposed as answer by DotNet Wang Wednesday, October 14, 2015 9:46 AM
    • Marked as answer by Youjun Tang Friday, October 16, 2015 5:19 AM
    Thursday, October 8, 2015 3:34 PM

All replies

  • Hi sansoft59,

    [Can anyone please guide me the steps to implement the function on the windows forms.]

    You could try below code.

    [DllImport("user32.dll", SetLastError=true)]
    private static extern bool SetProcessDPIAware();
    
    public static void Run()
    {
       SetProcessDPIAware();
    }
    Best Regards,
    Li Wang
    Thursday, October 8, 2015 2:33 AM
  • Hello Li,

    Thanks for your reply. But whenever I have tried to put in this code before the main entry point of the project, it affects the font sizes and the button alignments in a big way. Is there anything to make this look better.?

    Thursday, October 8, 2015 7:54 AM
  • Hi Sansoft

    I think the best idea is to apply the DPI aware setting then make the application look OK.

    If you don't do this then it will look bad when moved to another device that is very different.

    Hopefully if you set DPI awareness and then move it to another machine it will look approximately the same.

    • Proposed as answer by DotNet Wang Wednesday, October 14, 2015 9:46 AM
    • Marked as answer by Youjun Tang Friday, October 16, 2015 5:19 AM
    Thursday, October 8, 2015 3:34 PM
  • Hello,

    Thanks for your reply. But as per your advice

    "I think the best idea is to apply the DPI aware setting then make the application look OK."

    Do you mean that we should apply the code to the start of the application and then manually adjust the fonts and the field alignments of the affected forms. There are so many of them and its not possible to adjust the alignments at this stage. Please correct me if I am wrong.

    Also I just want the report print layout to scaled to the width which is just one form. Is there any way I can just apply to this form and leave others untouched ?

    Friday, October 16, 2015 10:02 AM
  • Hi Sansoft

    If you do this then move the application to a machine with an even higher DPI then it will look small again.

    Friday, October 16, 2015 10:09 AM