100分求问!!winform编写的窗口程序,如何在win7下忽略高DPI设置,不跟随其放大放大?

老鱼趣多多 2013-03-13 10:40:29
winform编写的窗口程序,本来可以正常显示。
当win7用户调整了DPI,也即在设置里进行了显示放大,界面就乱套了。


现在请问,winform编写的程序,如何能忽略该设置,不随其放大而变化?
...全文
1073 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
konanx 2013-04-05
  • 打赏
  • 举报
回复
使用WPF做界面。
老鱼趣多多 2013-03-22
  • 打赏
  • 举报
回复
该问题还是没有解决,期待答案。
dianjixue1 2013-03-14
  • 打赏
  • 举报
回复
引用 12 楼 tanghuawei 的回复:
将 Form 设置为this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; 控件都设置为 Control.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
这样设置固然是可以的,布局不会变,但是字体会放大。这样的话,如果是按钮、链接等控件,不会看起来不协调吗?有一种方式控制同时字体不会变大,控制界面不变比较好。 所以还是要窗体布局随着DPI的变化而变。否则的话,用户设置DPI不是就没有意义了吗? 有一些用户的屏幕尺寸小而显示器的分辨率大,他们就是希望放大DPI,调整显示效果。否则我们的窗体在屏幕中只显示一点点,也不好看。
assky124 2013-03-13
  • 打赏
  • 举报
回复
设置 Form 的 AutoScaleMode 属性不行么
dianjixue1 2013-03-13
  • 打赏
  • 举报
回复
DPI适应处理方式: 1.所有设置了BackgroundImage的控件背景图 BackgroundImageLayout 属性设置为Stretch 2.窗体打开后获取DPI系数

private void Form1_Load(object sender, EventArgs e)
        {
            //获取系统DPI
            try
            {
                SetProcessDPIAware();  //重要
                IntPtr screenDC = GetDC(IntPtr.Zero);
                int dpi_x = GetDeviceCaps(screenDC, /*DeviceCap.*/LOGPIXELSX);
                int dpi_y = GetDeviceCaps(screenDC, /*DeviceCap.*/LOGPIXELSY);
                CommonInfo.scaleUIX = dpi_x / 96.0;//横向系数
                CommonInfo.scaleUIY = dpi_y / 96.0;//纵向系数
                ReleaseDC(IntPtr.Zero, screenDC);
            }
            catch (Exception)
            {
                //throw;
                //没有管理员权限就获取不到了
            }
        }
/*----------------------------------------获取系统DPI-----------------------------------------------------*/
        [DllImport("user32.dll")]
        static extern IntPtr GetDC(IntPtr ptr);

        [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
        public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);

        [DllImport("gdi32.dll")]
        public static extern IntPtr CreateDC(
        string lpszDriver, // driver name
        string lpszDevice, // device name
        string lpszOutput, // not used; should be NULL
        Int64 lpInitData // optional printer data
        );

        [DllImport("gdi32.dll")]
        public static extern int GetDeviceCaps(
        IntPtr hdc, // handle to DC
        int nIndex // index of capability
        );

        [DllImport("user32.dll")]
        internal static extern bool SetProcessDPIAware();

        const int DRIVERVERSION = 0;
        const int TECHNOLOGY = 2;
        const int HORZSIZE = 4;
        const int VERTSIZE = 6;
        const int HORZRES = 8;
        const int VERTRES = 10;
        const int BITSPIXEL = 12;
        const int PLANES = 14;
        const int NUMBRUSHES = 16;
        const int NUMPENS = 18;
        const int NUMMARKERS = 20;
        const int NUMFONTS = 22;
        const int NUMCOLORS = 24;
        const int PDEVICESIZE = 26;
        const int CURVECAPS = 28;
        const int LINECAPS = 30;
        const int POLYGONALCAPS = 32;
        const int TEXTCAPS = 34;
        const int CLIPCAPS = 36;
        const int RASTERCAPS = 38;
        const int ASPECTX = 40;
        const int ASPECTY = 42;
        const int ASPECTXY = 44;
        const int SHADEBLENDCAPS = 45;
        const int LOGPIXELSX = 88;
        const int LOGPIXELSY = 90;
        const int SIZEPALETTE = 104;
        const int NUMRESERVED = 106;
        const int COLORRES = 108;
        const int PHYSICALWIDTH = 110;
        const int PHYSICALHEIGHT = 111;
        const int PHYSICALOFFSETX = 112;
        const int PHYSICALOFFSETY = 113;
        const int SCALINGFACTORX = 114;
        const int SCALINGFACTORY = 115;
        const int VREFRESH = 116;
        const int DESKTOPVERTRES = 117;
        const int DESKTOPHORZRES = 118;
        const int BLTALIGNMENT = 119;

所有后台生成的控件,比如Label lbl = new Label();这样生成的,控件的Location、Size属性,全部乘以得到的系数CommonInfo.scaleUIX、CommonInfo.scaleUIY
  • 打赏
  • 举报
回复
可以尝试下TableLayoutPanel,把控件放到格子里。
APM60- 2013-03-13
  • 打赏
  • 举报
回复
以前遇到过,好在设备都是自己的,可以自己设置,就没再去深究。 不知道能不能修改下设置尺寸的度量单位。 记得以前做网页的时候,文字大小的单位有一个是像素。 设置成其他单位时,则根据浏览器的设置显示大小不一样。
老鱼趣多多 2013-03-13
  • 打赏
  • 举报
回复
我测试过优化大师之类的软件,设置调整为150%,这些软件没有任何变化。 看来应该是忽略了这个放大效果。 请问,这个是怎么处理的?
cshas 2013-03-13
  • 打赏
  • 举报
回复
我刚试了下.所有程序都变了.有些问题还是随大流的好.
  • 打赏
  • 举报
回复
我之前也遇到过,没解决。、帮顶~~~~~~~~~~~~
老鱼趣多多 2013-03-13
  • 打赏
  • 举报
回复
顶起来,求问。
老鱼趣多多 2013-03-13
  • 打赏
  • 举报
回复
引用 12 楼 tanghuawei 的回复:
将 Form 设置为this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; 控件都设置为 Control.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
抱歉不理解您所谓这行代码:Control.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 好多控件都没有这个属性,比如button,比如pictrue控件都没有,怎么设置?
tanghuawei 2013-03-13
  • 打赏
  • 举报
回复
将 Form 设置为this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; 控件都设置为 Control.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
yjl1410 2013-03-13
  • 打赏
  • 举报
回复
解决过这个问题,,布局不受DPI影响,需要把主窗体,子窗体,以及控件的AutoScale全调整,还不行我给你远程协助
老鱼趣多多 2013-03-13
  • 打赏
  • 举报
回复
引用 9 楼 assky124 的回复:
设置 Form 的 AutoScaleMode 属性不行么
这个方法不好用。设置了之后,放大一下,仍然变形。

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧