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);
当我再次点击按钮时做下面处理
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是变小了,但是界面不变,还是加文本框后的大小,请问为什么?难道实现的不对么?
9 个解决方案
#1
断点,。。。。。。
#2
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);
{
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);
#3
我测试正常
#4
楼主是想变回原来大小吗?你的程序测试是对的,是有变化的,只是你的size设置的不是变回原来大小哦只有高度变了一点点,所以效果并不明显。
#5
看上去没神马问题
#6
你的代码没有问题哦,我同意4楼的说法!!!
#7
但是我打断点试过了啊,确实有问题的,当我再次点击按钮的时里的代码有问题,this.MaximumSize = new System.Drawing.Size(643, 427);this.Size = this.MaximumSize;这2断代码执行过后,SIZE不变,依然原来大小。。我感到很奇怪的。。为什么重新赋值后还是原来大小的。。
#8
不可能吧,我也用你的打断点试了,没有你说的这个问题。
#9
还是不行啊。。。难道我电脑有问题吗?
#1
断点,。。。。。。
#2
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);
{
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);
#3
我测试正常
#4
楼主是想变回原来大小吗?你的程序测试是对的,是有变化的,只是你的size设置的不是变回原来大小哦只有高度变了一点点,所以效果并不明显。
#5
看上去没神马问题
#6
你的代码没有问题哦,我同意4楼的说法!!!
#7
但是我打断点试过了啊,确实有问题的,当我再次点击按钮的时里的代码有问题,this.MaximumSize = new System.Drawing.Size(643, 427);this.Size = this.MaximumSize;这2断代码执行过后,SIZE不变,依然原来大小。。我感到很奇怪的。。为什么重新赋值后还是原来大小的。。
#8
不可能吧,我也用你的打断点试了,没有你说的这个问题。
#9
还是不行啊。。。难道我电脑有问题吗?