我有一个“普通”表单,用户可以调整它的大小等等。 如果他单击特定按钮,则 formBorderStyle 将更改为“无”,这样他就不能再调整它的大小,并且表单大小也不再是动态的。 发生这种情况后,代码应该从 Width & Height 返回。我通过使用
this.FormBorderStyle = FormBorderStyle.None;
mid.X = this.Width / 2;
mid.Y = this.Height / 2;
注意:“mid”只是一个普通点。
问题:
代码总是返回尺寸 1080; 720. 这是因为起始大小就是这样。该代码应该提供更改后的大小(例如,如果用户将表单大小更改为 2000;1000,它应该提供 2000;1000,而不是 1080;720。 为什么程序不更新大小值/为什么传递旧值?
谢谢!
编辑:
这是传递大小的完整事件:
private void button1_Click(object sender, EventArgs e)
{
button1.Visible = false;
this.FormBorderStyle = FormBorderStyle.None;
mid.X = this.Width / 2;
mid.Y = this.Height / 2;
drawerUpdateSchedule.Start();
}
最佳答案
检查 this 中接受的答案线程,看起来像你的问题的答案。特别是
private void Form1_Resize(object sender, System.EventArgs e)
{
Control control = (Control)sender;
//Access width and height withㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ
control.Size.Height;
control.Size.Width;
}
关于C# 'this.Width' 或 'this.Height' 在用户调整表单大小后返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29970567/