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:
- This. Resize + =NewEventhandler (form1_resize );
- // X =This. Width;
- 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.