欢迎来到天天文库
浏览记录
ID:43338412
大小:315.71 KB
页数:29页
时间:2019-09-30
《【精品】c#学习的心得》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、C#实现控件随窗体大小自动改变C#2009-12-1617:56:45阅读1207评论0字号:大中小订阅usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Collections;namespaceWindowsApplication3{publi
2、cpartialclassForml:Form{/**************设定程序中可能要用到的用以存储初始数据的动态数组及相关私冇变鼠******************************^privateArrayListInitialCrl=newArrayList();//用以存储窗体中所有的控件名称privateArrayListCrILocationX=newArrayList()//ffl以存储窗体中所有的控件原始位置privateArrayListCrILocationY=newArrayLi
3、st();//用以存储窗体中所有的控件原始位置privateArrayListCrISizeWidth=newArrayList();//用以存储窗体中所有的控件原始的水平尺寸privateArrayListCrISizeHeight=newArrayList();//用以存储窗体中所有的控件原始的垂直尺寸privateintFormSizeWidth;//用以存储窗体原始的水平尺寸privateintFormSizeHeight;//川以存储窗体原始的垂辽尺寸privatedoubleFormSizeChanged
4、X;//用以存储相关父窗体/容器的水平变化量privatedoubleFormSizeChangedY;//用以存储相关父窗体/容器的垂玄变化暈privateintWcounter=0;//为防I匕递归遍历控件时产生混乱,故专门设定一个全局计数器*/publicForml(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){GetlnitialFormSize();//this.AutoScroll=true;//this.S
5、etAutoSizeMode(FormSizeWidth,FormSizeHeight);//this.AutoScrollMinSize.Width=FormSizeWidth;//this.AutoScrollMinSize.Height=FormSizeHeight;GetAIICrlLocation(this);GetAIICrlSize(this);}publicvoidGetAIICrlLocation(ControlCrIContainer)//获得并存储窗体屮各控件的初始位置{foreach(Cont
6、roliCrlinCrIContainer.Controls){if(iCrl.Controls.Count>0)GetAIICrlLocation(iCrl);InitialCrl.Add(iCrl);CrILocationX.Add(iCrl.Location.X);CrILocationYAdd(iCrl.Location.Y);}}publicvoidGetAIICrlSize(ControlCrIContainer)//获得并存储窗体中各控件的初始尺寸{foreach(ControliCrlinCrICon
7、tainer.Controls){if(iCrl.Controls.Count>0)GetAIICrlSize(iCrl);CrlSizeWidth.Add(iCrl.Width);CrlSizeHeight.Add(iCrl.Height);}}publicvoidGetlnitialFormSize()//获得并存储窗体的初始尺寸{FormSizeWidth=this.Size.Width;FormSizeHeight=this.Size.Height;}privatevoidForm1_SizeChanged(
8、objectsender,EventArgse){//MessageBox.Show("窗体尺寸改变");Wcounter=0;intcounter=0;if(this.Size.Width9、10、this.Size.Height
9、
10、this.Size.Height
此文档下载收益归作者所有