本帖最后由 yuzhenhao 于 2013-03-13 10:41:03 编辑

解决方案 »

  1.   

    可以尝试下TableLayoutPanel,把控件放到格子里。
      

  2.   

    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
               
      

  3.   

    设置 Form 的 AutoScaleMode 属性不行么
      

  4.   

    解决过这个问题,,布局不受DPI影响,需要把主窗体,子窗体,以及控件的AutoScale全调整,还不行我给你远程协助
      

  5.   

    将 Form 设置为this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;控件都设置为
    Control.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
      

  6.   


    抱歉不理解您所谓这行代码:Control.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;好多控件都没有这个属性,比如button,比如pictrue控件都没有,怎么设置?
      

  7.   


    这样设置固然是可以的,布局不会变,但是字体会放大。这样的话,如果是按钮、链接等控件,不会看起来不协调吗?有一种方式控制同时字体不会变大,控制界面不变比较好。
    所以还是要窗体布局随着DPI的变化而变。否则的话,用户设置DPI不是就没有意义了吗?
    有一些用户的屏幕尺寸小而显示器的分辨率大,他们就是希望放大DPI,调整显示效果。否则我们的窗体在屏幕中只显示一点点,也不好看。
      

  8.   

    参考:http://stackoverflow.com/questions/4089237/how-do-i-force-a-winform-c-sharp-application-to-ignore-when-a-user-choose-125-o