usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceCSharpFormApplication
{classAutoResizeForm
{//(1).声明结构,只记录窗体和其控件的初始位置和大小。
public structcontrolRect
{public intLeft;public intTop;public intWidth;public intHeight;
}//(2).声明 1个对象//注意这里不能使用控件列表记录 List nCtrl;,因为控件的关联性,记录的始终是当前的大小。//public List oldCtrl= new List();//这里将西文的大于小于号都过滤掉了,只能改为中文的,使用中要改回西文
public List oldCtrl = new List();int ctrlNo = 0;//1;//(3). 创建两个函数//(3.1)记录窗体和其控件的初始位置和大小,
public voidcontrollInitializeSize(Control mForm)
{
controlRect cR;
cR.Left= mForm.Left; cR.Top = mForm.Top; cR.Width = mForm.Width; cR.Height =mForm.Height;
oldCtrl.Add(cR);//第一个为"窗体本身",只加入一次即可
AddControl(mForm);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用//this