PublicForm1 () {InitializeComponent (); intCount = This. Controls.Count *2+2; float[] factor =New float[Count]; inti =0; Factor[i++] =Size.width; Factor[i++] =Size.Height; foreach(Control Ctrlinch This. Controls) {Factor[i+ +] = Ctrl. Location.x/(float) Size.width; Factor[i+ +] = Ctrl. LOCATION.Y/(float) Size.Height; Ctrl. Tag=Ctrl. Size; } Tag=factor; } Private voidForm1_Resize (Objectsender, EventArgs e) { float[] Scale = (float[]) Tag; inti =2; foreach(Control Ctrlinch This. Controls) {Ctrl. Left= (int) (Size.width * scale[i++]); Ctrl. Top= (int) (Size.Height * scale[i++]); Ctrl. Width= (int) (Size.width/(float) scale[0] *((Size) Ctrl. TAG). Width); Ctrl. Height= (int) (Size.Height/(float) scale[1] *((Size) Ctrl. TAG). Height); //each use is the most initial control size, guaranteed to be accurate. } }
The controls in the window change the size of the control with the size of the form