How to avoid screen bouncing when adding a new MDI Child Window

心已入冬 提交于 2020-08-10 19:04:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!