问题
In my MDI Frame, I'm creating MDI Child Windows as follows:
Form frm = new frmMyChild();
frm.MdiParent = this;
frm.WindowState = FormWindowState.Maximized;
frm.Show();
frm.Focus();
So far, this works good, but the screen is shortly "bouncing", because the child windows are put to "normal" state, and then they are maximized again. How can this be prevented?
回答1:
Even if a MenuStrip is added to a MDI Parent Form, the Form.MainMenuStrip is still null
.
When this property is null
, the System Menu controls of the MDI child are not blended with the MenuStrip (or the old MainMenu
), so the child Form title bar is still visible and positioned above the MenuStrip.
When a new child Form is created and maximized, the MenuStrip bounces up and down while the child Form Caption is recreated.
Setting the MainMenuStrip
property to the instance of the MDI Parent's MenuStrip, will cause the System Menu controls of the MDI child to blend with the MenuStrip (or the MainMenu
).
It's interesting to see in the .Net Source Code how many times this behavior and the design have changed over time (and it's just the comments there :).
TheMDIMenuStrip
is the MDI Parent's MenuStrip created at Design Time and initialized in InitializeComponent()
.
public partial class MDIParent : Form
{
public MDIParent()
{
InitializeComponent();
this.MainMenuStrip = this.TheMDIMenuStrip;
this.TheMDIMenuStrip.SendToBack();
}
...
}
Before:
After:
来源:https://stackoverflow.com/questions/59673471/how-to-avoid-screen-bouncing-when-adding-a-new-mdi-child-window