The main way to implement this is to use the Panel control as the theme, to record the size position and font properties of each control, and then to shrink the size of the form as it changes.
The brief steps are as follows:
1. Create a C # form program project.
2. The panel is placed on the form.
3, set properties dock for fill.
4, note that minnumsize can not be set to 0, changed to more than 0 are OK.
Copy Code code as follows:
public partial class Frmdemo:form
{
Double dfrmwidth;
Double dfrmheight;
Double Dzoomhorizon;
Double dzoomverticality;
dictionary<string, string> diccontrolsattribute = new dictionary<string, string> ();
protected void Getallinitiatecontrlinfo (Control Crlcontainer)
{
if (crlcontainer.parent = = this)
{
Dfrmwidth = convert.todouble (crlcontainer.width);
Dfrmheight = convert.todouble (crlcontainer.height);
}
foreach (Control item in Crlcontainer.controls)
{
if (item. Name.trim ()!= "")
Diccontrolsattribute.add (item. Name, (item. Left + item. WIDTH/2) + "," + (item. Top + item. HEIGHT/2)
+ "," + Item. Width + "," + Item. Height + "," + Item. Font.Size);
if (item as UserControl) = = NULL && item. Controls.Count > 0)
Getallinitiatecontrlinfo (item);
}
}
private void Changecontrolsinitiate (Control Crlcontainer)
{
Dzoomhorizon = (convert.todouble (crlcontainer.width)/dfrmwidth);
Dzoomverticality = (convert.todouble (crlcontainer.height)/dfrmheight);
}
private void Changecurrentcontrolattr (Control Crlcontainer)
{
double[] dposition = new DOUBLE[5];
foreach (Control item in Crlcontainer.controls)
{
if (item. Name.trim ()!= "")
{
if (item as UserControl) = = NULL && item. Controls.Count > 0)
Changecurrentcontrolattr (item);
string[] STRs = Diccontrolsattribute[item. Name]. Split (', ');
for (int j = 0; J < 5, j + +)
{
DPOSITION[J] = convert.todouble (Strs[j]);
}
Double itemwidth = dposition[2] * DZOOMHORIZON;
Double itemheight = dposition[3] * dzoomverticality;
Item. left = Convert.ToInt32 (dposition[0] * DZOOMHORIZON-ITEMWIDTH/2);
Item. top = Convert.ToInt32 (dposition[1] * DZOOMVERTICALITY-ITEMHEIGHT/2);
Item. Width = Convert.ToInt32 (itemwidth);
Item. Height = Convert.ToInt32 (itemheight);
Item. Font = new Font (item. Font.Name, float. Parse
((dposition[4] * math.min (Dzoomhorizon, dzoomverticality)). ToString ()));
The font can also be reduced to a year.
}
}
}
protected override void Onsizechanged (EventArgs e)
{
Base. Onsizechanged (e);
if (Diccontrolsattribute.count > 0)
{
Changecontrolsinitiate (this. Controls[0]);
Changecurrentcontrolattr (this. Controls[0]);
}
}
Public Frmdemo ()
{
InitializeComponent ();
Getallinitiatecontrlinfo (this. Controls[0]);//The constructor can be called inside.
}
}
5. Effect Test