添加新的MDI子窗口时如何避免屏幕跳动 [英] How to avoid screen bouncing when adding a new MDI Child Window

查看:39
本文介绍了添加新的MDI子窗口时如何避免屏幕跳动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的MDI框架中,按如下方式创建MDI子窗口:

  Form frm = new frmMyChild();frm.MdiParent = this;frm.WindowState = FormWindowState.Maximized;frm.Show();frm.Focus(); 

到目前为止,这很好,但是屏幕很快就会弹起",因为子窗口被置于正常"状态,然后再次最大化它们.如何预防呢?

解决方案

即使将MenuStrip添加到MDI父窗体,

之前最大化

之后:

之后最大化

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?

解决方案

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:

这篇关于添加新的MDI子窗口时如何避免屏幕跳动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆