Search code examples
c#winformsscreen-resolution

My Windows Forms application size is changing on different notebooks


Coding my project was going well. But today I noticed a problem.

My main notebook has full hd (1920x1080) resolution and I am coding my projects here. When I changed my main notebook's resolution to 1280x1024, 1280x800, or 1024x768 there is no problem. My application's resolution is 1024x768 and it is not collapsing. This is the printscreen.

Normal screen

But my other notebook has 1366x768 resolution. And I am running my application on this notebook. Oh! There is a disappointment. My application screen shifted. This is the bad printscreen.

Bad screen

I do not understand why. What can I do correcting this error?


Solution

  • It arises from different DPI settings. You can do this in the form load:

    // Get DPI width
    float x = this.CreateGraphics().DpiX;
    
    // If screen is width
    if (x == 120)
        // Get big image from Resources
        this.BackgroundImage = Properties.Resources.BigImage;
    else
        // Get small image from Resources
        this.BackgroundImage = Properties.Resources.SmallImage;