WINFORM 自适应分辨率问题.
我的系统主窗口中有好多控件,在1024*768时,显示没问题,改为800*600后,有些控件就显示不出来了,手动改变窗口大小时,也会出现这样的情况,在网上没搜到好的解决办法,请高手指点.谢谢!
------解决方案--------------------很容易吧
定义变量如下
private List <double> dPresentW = new List <double> ();
private List <double> dPresentH = new List <double> ();
private List <double> dPresentT = new List <double> ();
private List <double> dPresentL = new List <double> ();
补充构造函数,例如:
public Form1()
{
InitializeComponent();
foreach (Control ctl in this.Controls)
{
dPresentW.Add((double)ctl.Width / (double)Width);
dPresentH.Add((double)ctl.Height / (double)Height);
dPresentT.Add((double)ctl.Top / (double)Height);
dPresentL.Add((double)ctl.Left / (double)Height);
}
}
然后写ReSize事件
private void Form1_Resize(object sender, EventArgs e)
{
int iCount = Controls.Count;
for (int i = 0; i < iCount; i++)
{
Controls[i].Left = (int)(Width * dPresentL[i]);
Controls[i].Top = (int)(Height * dPresentT[i]);
Controls[i].Width = (int)(Width * dPresentW[i]);
Controls[i].Height = (int)(Height * dPresentH[i]);
}
}