/**********************************c# the code implementation control with the form of the free transformation ********************************************/
Article Source: Star Soul Studio Author: Moon Cloud
2008.8.4
/**********************************************************************************************************/
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Text;
Using System.Windows.Forms;
Using System.Collections;
Namespace WindowsApplication3
{
public partial class Form1:form
{
/******************* dynamic arrays and associated private variables that may be used in the Setup program to store the initial data ******************************/
Private ArrayList initialcrl = new ArrayList ()//to store all control names on the form
Private ArrayList Crllocationx = new ArrayList ()//to store all the controls in the form in the original location
Private ArrayList crllocationy = new ArrayList ()//to store all the controls in the form in the original location
Private ArrayList crlsizewidth = new ArrayList ()//to store the original horizontal dimensions of all controls in the form
Private ArrayList crlsizeheight = new ArrayList ()//to store all the controls in the form in their original vertical dimensions
private int formsizewidth;//to store the original horizontal dimensions of the form
private int formsizeheight;//to store the original vertical dimensions of the form
Private double formsizechangedx;//to store the horizontal change of the related parent form/container
Private double formsizechangedy;//to store the vertical variation of the related parent form/container
private int wcounter = 0;//Creates a global counter specifically to prevent confusion when iterating over controls recursively
/************************************************************************************************************** **/
Public Form1 ()
{
InitializeComponent ();
}
private void Form1_Load (object sender, EventArgs e)
{
Getinitialformsize ();
This. AutoScroll = true;
This. Setautosizemode (Formsizewidth,formsizeheight);
This. Autoscrollminsize.width = Formsizewidth;
This. Autoscrollminsize.height = Formsizeheight;
Getallcrllocation (this);
Getallcrlsize (this);
}
public void Getallcrllocation (Control Crlcontainer)/Gets and stores the initial position of the controls in the form
{
foreach (Control icrl in Crlcontainer.controls)
{
if (ICrl.Controls.Count > 0)
Getallcrllocation (ICRL);
Initialcrl.add (ICRL);
Crllocationx.add (icrl.location.x);
Crllocationy.add (ICRL.LOCATION.Y);
}
}
public void Getallcrlsize (Control Crlcontainer)/Gets and stores the initial dimensions of the controls in the form
{
foreach (Control icrl in Crlcontainer.controls)
{
if (ICrl.Controls.Count > 0)
Getallcrlsize (ICRL);
Crlsizewidth.add (Icrl.width);
Crlsizeheight.add (Icrl.height);
}
}
public void Getinitialformsize ()//Gets and stores the initial size of the form
{
Formsizewidth = this. Size.width;
Formsizeheight = this. Size.Height;
}
private void Form1_sizechanged (object sender, EventArgs e)
{
MessageBox.Show ("Form size change");
Wcounter = 0;
int counter = 0;
if (this. Size.width < Formsizewidth | | This. Size.Height < Formsizeheight)
If the size of the form is less than the initial value of the form size, the controls in the form are automatically reset to the initial dimensions, and the form automatically adds scroll bars
{
foreach (Control inicrl in INITIALCRL)
{
Inicrl.width = (int) crlsizewidth[counter];
Inicrl.height = (int) crlsizeheight[counter];
Point point = new Point ();
Point. X = (int) crllocationx[counter];
Point. Y = (int) crllocationy[counter];
Inicrl.bounds = new Rectangle (point, inicrl.size);
counter++;
}
This. AutoScroll = true;
}
Else
Otherwise, reset the size of all controls on the form (the size of all controls in the window changes with the size of the form)
{
This. AutoScroll = false;
Resetallcrlstate (this);
}
}
public void Resetallcrlstate (Control Crlcontainer)/reset the state of the controls in the form (calculated in contrast to the original state)
{
Formsizechangedx = (double) this. Size.width/(double) formsizewidth;
Formsizechangedy = (double) this. Size.Height/(double) formsizeheight;
foreach (Control kcrl in Crlcontainer.controls)
{
/*string name = KCrl.Name.ToString ();
MessageBox.Show (name);
MessageBox.Show (Wcounter.tostring ());
if (KCrl.Controls.Count > 0)
{
Resetallcrlstate (KCRL);
}
Point point = new Point ();
Point. X = (int) ((int) crllocationx[wcounter] * Formsizechangedx);
Point. Y = (int) ((int) crllocationy[wcounter] * formsizechangedy);
Kcrl.width = (int) ((int) crlsizewidth[wcounter] * Formsizechangedx);
Kcrl.height = (int) ((int) crlsizeheight[wcounter] * formsizechangedy);
Kcrl.bounds = new Rectangle (point, kcrl.size);
wcounter++;
MessageBox.Show (Wcounter.tostring ());
}
}
}
}