C # modify the Form Control with the form size (including the font size)

Source: Internet
Author: User

Private float X;

Private float y;

Private void settag (control cons)
{
Foreach (control con in cons. Controls)
{
Con. tag = con. width + ":" + con. height + ":" + con. left + ":" + con. top + ":" + con. font. size;
If (con. Controls. Count> 0)
Settag (CON );
}
}
Private void setcontrols (float newx, float newy, control cons)
{
Foreach (control con in cons. Controls)
{

String [] mytag = con. Tag. tostring (). Split (New char [] {':'});
Float a = convert. tosingle (mytag [0]) * newx;
Con. width = (INT);
A = convert. tosingle (mytag [1]) * newy;
Con. Height = (INT) ();
A = convert. tosingle (mytag [2]) * newx;
Con. Left = (INT) ();
A = convert. tosingle (mytag [3]) * newy;
Con. Top = (INT) ();
Single currentsize = convert. tosingle (mytag [4]) * Math. Min (newx, newy );
Con. font = new font (con. Font. Name, currentsize, Con. Font. style, Con. Font. Unit );
If (con. Controls. Count> 0)
{
Setcontrols (newx, newy, con );
}
}

}

Void form1_resize (Object sender, eventargs E)
{
Float newx = (this. width)/X;
Float newy = This. Height/y;
Setcontrols (newx, newy, this );
This. Text = This. Width. tostring () + "" + this. Height. tostring ();

}

 

Add the following in form_load:

    1. This. Resize + =NewEventhandler (form1_resize );
    2. // X =This. Width;
    • // Y =This. Height;

      • Settag (This);
      • Form1_resize (new object (), new eventargs (); // X, Y can be assigned during instantiation. This sentence is newly added and is useful in MDI.
Related Article

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.