C#界面大小改变问题
界面的最大SIZE和最小SIZE是没有设置的,因为我需要界面变化,当我点击一个按钮时做以下处理
C# code
this.MaximizeBox = true;
this.MaximumSize = new System.Drawing.Size(643, 478);
this.Size = this.MaximumSize;
this.MinimumSize = this.MaximumSize;
this.panel.Size = new System.Drawing.Size(603, 330);
this.MaximizeBox = false;
this.panel.Controls.Add(textBox1);
当我再次点击按钮时做下面处理
C# code
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(643, 427);
this.Size = this.MaximumSize;
this.panel.Controls.Remove(textBox1);
this.panel.Size = new System.Drawing.Size(603, 279);
但是有问题,第一次点击按钮界面是变大了,PANEL也变大了,文本框也加上了,再次点击按钮的时候,那个PANEL是变小了,但是界面不变,还是加文本框后的大小,请问为什么?难道实现的不对么?
------解决方案--------------------private void ResizeInit(Form frm)
{
oldFrmWidth = frm.Width;
oldFrmHeight = frm.Height;
foreach (Control control in frm.Controls)
{
control.Tag = control.Left.ToString() + "," + control.Top.ToString() + ","
+ control.Width.ToString() + "," + control.Height.ToString();
}
}
private void MainForm_SizeChanged(object sender, EventArgs e)
{
float ScaleX;
float ScaleY;
Form f = (Form)sender;
ScaleX = (float)f.Width / oldFrmWidth;
ScaleY = (float)f.Height / oldFrmHeight;
venuesControl1.setSize(ScaleX, ScaleY);
foreach (Control c in f.Controls)
{
string[] tmp = c.Tag.ToString().Split(',');
c.Left = (int)(Convert.ToInt16(tmp[0]) * ScaleX);
c.Top = (int)(Convert.ToInt16(tmp[1]) * ScaleY);
c.Width = (int)(Convert.ToInt16(tmp[2]) * ScaleX);
c.Height = (int)(Convert.ToInt16(tmp[3]) * ScaleY);
}
}
load里面添加ResizeInit(this);
------解决方案--------------------