我正在处理一个遗留的WinForms MDI应用程序,并且在使子窗体按照我的意愿行事方面遇到了一些问题。我的目标是让子窗体始终最大化(停靠)。
问题在于,即使我将MaximizeBox设置为false,最大化/调整大小按钮也会出现在MDIs工具栏中,让用户调整大小(取消停靠)子窗体。唯一的方法是将ControlBox设置为false,但那时关闭按钮也会消失(这不是我想要的)。
我已经尝试过使用固定的FormBorderStyle并在触发调整大小事件时最大化子窗体,但我的所有尝试都没有奏效。
我错过了什么超级秘密属性,还是这根本不可能?
最好的问候和提前致谢
问题在于,即使我将MaximizeBox设置为false,最大化/调整大小按钮也会出现在MDIs工具栏中,让用户调整大小(取消停靠)子窗体。唯一的方法是将ControlBox设置为false,但那时关闭按钮也会消失(这不是我想要的)。
我已经尝试过使用固定的FormBorderStyle并在触发调整大小事件时最大化子窗体,但我的所有尝试都没有奏效。
我错过了什么超级秘密属性,还是这根本不可能?
最好的问候和提前致谢
//All child forms derive from ChildForm
//Parent MDI Form implementation
//...
private void ShowForm(ChildForm form)
{
//Check if an instance of the form already exists
if (Forms.Any(x => x.GetType() == form.GetType()))
{
var f = Forms.First(x => x.GetType() == form.GetType());
f.Focus();
f.WindowState = FormWindowState.Maximized;
}
else
{
//Set the necessary properties (any other properties are set to default values)
form.MdiParent = this;
form.MaximizeBox = false;
form.MinimizeBox = false;
form.WindowState = FormWindowState.Maximized;
Forms.Add(form);
form.Forms = Forms;
form.Show();
form.Focus();
//Lets make it nasty (some forms aren't rendered properly otherwise)
form.WindowState = FormWindowState.Normal;
form.WindowState = FormWindowState.Maximized;
}
}
//...
//ChildForm implementation
//...
public List<Form> Forms { get; set; }
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
Forms.RemoveAll(x => x.GetType() == GetType());
}
protected override void OnResize(EventArgs e)
{
WindowState = FormWindowState.Maximized;
}