C # implements the controls for each control in a form to be automatically indented _mongodb

Source: Internet
Author: User
Tags trim

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

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.