我正在处理其他人编写的旧代码。在这种情况下,Windows.Forms.Form
在另一个主类中创建了一个子类Windows.Forms.Form
class MainForm : Windows.Forms.Form
{
m_subForm = null;
/* Much more stuff */
private void createSubForm
{
m_subForm= new SubForm();
m_subForm.Text = "";
m_subForm.MdiParent = this;
m_subForm.WindowState = FormWindowState.Maximized;
m_subForm.ControlBox = false;
m_subForm.Show();
// There is no comment in the code on why this is done:
this.Height -= 1;
this.Height += 1;
}
}
最后两行让我感到困惑。它们实际上是必要的,因为如果省略它们,主窗体中的窗体会在边缘周围被切掉。只有在您手动缩放屏幕后,子表单才会再次适合主表单。如果尝试将+=
-=
hack 替换为:
this.Refresh();
但这并不能解决问题。显然,这只会刷新主表单,但不会刷新子表单。如果没有这个丑陋的黑客,我该如何纠正这个问题?