问题描述
窗体的Panel控件中有Label,Textbox,Combox,Button等控件,因为Form在启动后就会最大化,那么它的控件如何随之也按比例最大化呢?
解决方案
解决方案二:
'在窗体中添加一个TextBox1,写入以下代码,可以看到效果'其他控件也是一样的写法PublicClassForm1PrivateSubForm1_Load(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesMe.LoadTextBox1.Multiline=TrueTextBox1.Width=Me.Width*0.7TextBox1.Height=Me.Height*0.7EndSubPrivateSubForm1_Resize(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesMe.ResizeTextBox1.Width=Me.Width*0.7TextBox1.Height=Me.Height*0.7EndSubEndClass
解决方案三:
楼上说了个思路,我写了程序给你usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespace经典测试2{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();foreach(Controlctlinthis.Controls){dPresentW.Add((double)ctl.Width/(double)Width);dPresentH.Add((double)ctl.Height/(double)Height);dPresentT.Add((double)ctl.Top/(double)Height);dPresentL.Add((double)ctl.Left/(double)Height);}}privateList<double>dPresentW=newList<double>();privateList<double>dPresentH=newList<double>();privateList<double>dPresentT=newList<double>();privateList<double>dPresentL=newList<double>();privatevoidForm1_Resize(objectsender,EventArgse){intiCount=Controls.Count;for(inti=0;i<iCount;i++){Controls[i].Left=(int)(Width*dPresentL[i]);Controls[i].Top=(int)(Width*dPresentT[i]);Controls[i].Width=(int)(Width*dPresentW[i]);Controls[i].Height=(int)(Height*dPresentH[i]);}}}}
解决方案四:
好长时间没登录了,谢谢两位师兄!