I am working on a legacy WinForms MDI application and am experiencing certain issues with the fact that child forms behave the way I want. My goal is to ensure that the shape of the child is always maximized (docked).
The problem is that even if I set MaximizeBox
to false
, the maximize / resize button appears in the MDI toolbar and allows the user to resize (unpin) the child form. The only way to avoid this is to set the ControlBox
to false
, but then the close button will disappear (this is not what I want).
I already tried using a fixed FormBorderStyle
and maximizing the child form when the resize event was FormBorderStyle
, but none of my approaches worked.
Is there any top-secret property that I missed, or is it just not possible?
Best regards and thanks in advance
Update
I wrote a messy method (thanks to @rfresia) to handle my child form, this may help others who are facing the same problem:
//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; }
Jay
source share