我的 Windows 窗体应用程序大小在不同的笔记本上发生变化 [英] My Windows Forms application size is changing on different notebooks
问题描述
我的项目编码进展顺利.但是今天我发现了一个问题.
Coding my project was going well. But today I noticed a problem.
我的主要笔记本具有全高清 (1920x1080) 分辨率,我正在这里编写我的项目.当我将主笔记本的分辨率更改为 1280x1024、1280x800 或 1024x768 时,没有问题.我的应用程序的分辨率是 1024x768 并且没有崩溃.这是打印屏幕.
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.
但我的另一台笔记本的分辨率为 1366x768.我正在这个笔记本上运行我的应用程序.哦!有一种失望.我的应用程序屏幕移动了.这是坏的打印屏幕.
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.
我不明白为什么.我能做些什么来纠正这个错误?
I do not understand why. What can I do correcting this error?
推荐答案
它源于不同的 DPI 设置.您可以在表单加载中执行此操作:
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;
这篇关于我的 Windows 窗体应用程序大小在不同的笔记本上发生变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!