Winform form controls resize with the form automatically (proportional)

Source: Internet
Author: User

New Form program, add form event load (when loading form), Resize (resize control for large hours). Custom method Settag (Gets the value of the control's width, height, left, top, font size, and so on), Setcontrols (resizes the control based on the size of the form).

1         floatX, Y;//x represents the width of the form, and y indicates the height of the form2         Private voidForm1_Load (Objectsender, EventArgs e)3         {4             //This . Resize + = new EventHandler (form1_resize);5X = This. Width;//Assignment Initial Form width6Y = This. Height;//Assignment Initial Form height7Settag ( This);8         }9         /// <summary>Ten         ///resizing controls for large hours One         /// </summary> A         /// <param name= "Sender" ></param> -         /// <param name= "E" ></param> -         Private voidForm1_Resize (Objectsender, EventArgs e) the         { -             floatNEWX = This. width/x;//gets the ratio of the current width to the initial width -             floatNewy = This. height/y;//gets the ratio of the current height to the initial height -Setcontrols (Newx, Newy, This); +              This. Text ="form width:"+ This. Width.tostring () +"form High:"+ This. Height.tostring ();//Form title bar -         } +         /// <summary> A         ///gets the value of the control's width, height, left, top, font size at         /// </summary> -         /// <param Name= "Cons" >the control to get information about</param> -         Private voidSettag (Control cons) -{//traversing controls in a form -             foreach(Control coninchcons. Controls) -             { inCon. Tag = con. Width +":"+ Con. Height +":"+ Con. Left +":"+ Con. Top +":"+con. Font.Size; -                 //if (con. Controls.Count > 0) to                 //{ +                 //Settag (con); -                 //} the             } *         } $         /// <summary>Panax Notoginseng         ///Sizing controls based on form size -         /// </summary> the         /// <param name= "newx" ></param> +         /// <param name= "Newy" ></param> A         /// <param name= "Cons" ></param> the         Private voidSetcontrols (floatNEWX,floatNewy, Control cons) +         { -             //to traverse a control in a form, reset the value of the control $             foreach(Control coninchcons. Controls) $             { -                 string[] MyTag = con. Tag.tostring (). Split (New Char[] {':'});//gets the value of the control's Tag property, and then stores the string array after splitting -  the                 floatA = Convert.tosingle (mytag[0]) * NEWX;//determines the value of the control based on the scale of the form, width//89*300 -Con. Width = (int) (a);//widthWuyi  theA = Convert.tosingle (mytag[1]) * NEWY;//determines the value of a control based on the scale of the form, height//12*300 -Con. Height = (int) (a);//Height Wu  -A = Convert.tosingle (mytag[2]) * NEWX;//determines the value of the control based on the scale of the form, left distance// AboutCon. left = (int) (a);//left distance $  -A = Convert.tosingle (mytag[3]) * NEWY;//determines the value of the control based on the scale of the form, the top edge distance -Con. Top = (int) (a);//Top edge Distance -  ASingle currentsize = Convert.tosingle (mytag[4]) * NEWY;//determines the value of the control based on the scale of the form, font size +Con. Font =NewFont (Con. Font.Name, CurrentSize, con. Font.style, Con. Font.unit);//Font Size the  -                 //if (con. Controls.Count > 0) $                 //{ the                 //Setcontrols (newx, newy, con); the                 //} the  the                 //Remarks: -                 //Control Current width: control initial width = form current width: form initial height in                 //Control Current width = initial width of control * (Form current width/form initial height) the             } the}

Reference: http://jingyan.baidu.com/article/77b8dc7fe801006174eab6db.html

Winform form controls resize with the form automatically (proportional)

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.