小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

C#中代碼實(shí)現(xiàn)控件隨窗體的自由變換

 sanxuxbr 2011-01-12

 

/**********************************C#中代碼實(shí)現(xiàn)控件隨窗體的自由變換********************************************/ 


// 文章出處: 星魂工作室 作者:月云

// 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
{
/*******************設(shè)定程序中可能要用到的用以存儲初始數(shù)據(jù)的動態(tài)數(shù)組及相關(guān)私有變量******************************/

private ArrayList InitialCrl = new ArrayList();//用以存儲窗體中所有的控件名稱
private ArrayList CrlLocationX = new ArrayList();//用以存儲窗體中所有的控件原始位置
private ArrayList CrlLocationY = new ArrayList();//用以存儲窗體中所有的控件原始位置
private ArrayList CrlSizeWidth = new ArrayList();//用以存儲窗體中所有的控件原始的水平尺寸
private ArrayList CrlSizeHeight = new ArrayList();//用以存儲窗體中所有的控件原始的垂直尺寸
private int FormSizeWidth;//用以存儲窗體原始的水平尺寸
private int FormSizeHeight;//用以存儲窗體原始的垂直尺寸

private double FormSizeChangedX;//用以存儲相關(guān)父窗體/容器的水平變化量
private double FormSizeChangedY;//用以存儲相關(guān)父窗體/容器的垂直變化量

private int Wcounter = 0;//為防止遞歸遍歷控件時產(chǎn)生混亂,故專門設(shè)定一個全局計數(shù)器

/****************************************************************************************************************/


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)//獲得并存儲窗體中各控件的初始位置
{
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)//獲得并存儲窗體中各控件的初始尺寸
{
foreach (Control iCrl in CrlContainer.Controls)
{
if (iCrl.Controls.Count > 0)
GetAllCrlSize(iCrl);
CrlSizeWidth.Add(iCrl.Width);
CrlSizeHeight.Add(iCrl.Height);
}
}

public void GetInitialFormSize()//獲得并存儲窗體的初始尺寸
{

FormSizeWidth
= this.Size.Width;
FormSizeHeight
= this.Size.Height;

}

private void Form1_SizeChanged(object sender, EventArgs e)
{
// MessageBox.Show("窗體尺寸改變");
Wcounter = 0;
int counter = 0;
if (this.Size.Width < FormSizeWidth || this.Size.Height < FormSizeHeight)
//如果窗體的大小在改變過程中小于窗體尺寸的初始值,則窗體中的各個控件自動重置為初始尺寸,且窗體自動添加滾動條
{

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
//否則,重新設(shè)定窗體中所有控件的大?。ù绑w內(nèi)所有控件的大小隨窗體大小的變化而變化)
{
this.AutoScroll = false;
ResetAllCrlState(
this);
}


}

public void ResetAllCrlState(Control CrlContainer)//重新設(shè)定窗體中各控件的狀態(tài)(在與原狀態(tài)的對比中計算而來)
{


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());


}
}


}


}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多