窗口根据屏幕分辨率自动调整大小

来源:互联网 发布:linux c 11 多线程 编辑:程序博客网 时间:2024/05/17 07:45

double xrate ;
 double yrate ;

 

//构造函数中

Rectangle rect = new Rectangle();
            rect = Screen.GetWorkingArea(this);
            xrate = rect.Width / 1024.0;
            yrate = rect.Height / 738.0;
            controlRsize((Control)this);

 

 

//控件大小、位置调整函数

 private void controlRsize(Control cr)
      {
          
          if (cr.Controls.Count == 0)
          {
              cr.Width = (int)(cr.Width * xrate);
              cr.Height = (int)(cr.Height * yrate);
              return;
          }
          else
          {
              cr.Width = (int)(cr.Width * xrate);
              cr.Height = (int)(cr.Height * yrate);
              if (cr.Dock==DockStyle.None)
              {
                  cr.Location = new Point((int)(cr.Location.X * xrate),(int)(cr.Location.Y * yrate));
              }
              foreach (Control obj in cr.Controls)
                  controlRsize(obj);
          }
      }

 

 

 

原创粉丝点击