Original C # proportionally scales form controls and fonts

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.