Scale the form controls and fonts proportionally, and if you want to scale them proportionally, simply set the scale of X, y to the same.
To reduce the error, it is recommended to use the original size to calculate the scale.
1 Private floatX, Y;2 3 Private BOOLb =false;4 5 Publicmainform ()6 {7 InitializeComponent ();8 9X = This. Width;TenY = This. Height; One ASettag ( This); - -b =true; the } - - protected Override voidonsizechanged (EventArgs e) - { + if(!B)return; - + floatNewx = ( This. Width)/X; A floatNewy = This. Height/Y; atSetcontrols (Newx, Newx, This); - - Base. Onsizechanged (e); - } - - /// <summary> in ///storing raw control parameters - /// </summary> to /// <param name= "Cons" ></param> + Private voidSettag (Control cons) - { the foreach(Control coninchcons. Controls) * { $Con. Tag = con. Width +":"+ Con. Height +":"+ Con. Left +":"+ Con. Top +":"+con. Font.Size;Panax Notoginseng if(Con. Controls.Count >0) - Settag (con); the } + } A the /// <summary> + ///Scale control size and font by scaling - /// </summary> $ /// <param name= "newx" ></param> $ /// <param name= "Newy" ></param> - /// <param name= "Cons" ></param> - Private voidSetcontrols (floatNEWX,floatNewy, Control cons) the { - foreach(Control coninchcons. Controls)Wuyi { the string[] MyTag = con. Tag.tostring (). Split (New Char[] {':' }); - intwidth = (int) (Convert.tosingle (mytag[0]) *newx); Wu intHeight = (int) (Convert.tosingle (mytag[1]) *newy); - intx = (int) (Convert.tosingle (mytag[2]) *newx); About inty = (int) (Convert.tosingle (mytag[3]) *newy); $Con. Location =NewPoint (x, y); -Con. Size =NewSystem.Drawing.Size (width, height); -Single currentsize = Convert.tosingle (mytag[4]) *Newy; -Con. Font =NewFont (Con. Font.Name, CurrentSize, con. Font.style, Con. Font.unit); A + if(Con. Controls.Count >0) the { - Setcontrols (newx, newy, con); $ } the } the}
Code
Original C # proportionally scales form controls and fonts