Restore事件后表单大小的问题

时间:2011-04-11 08:23:06

标签: c# .net mdi

我有一个包含1个父表单和3个子表单的Mdi应用程序。 父表单大小始终如下计算:

this.Size = ActiveMdiChild.Size;
this.Height +=150; // because there is a control at the bottom of Parent form

问题是,当我最小化Parent Form,然后恢复它时,恢复后它的大小减少了20个。所以表单看起来有点失真。在我的代码中,我没有指定它来减小它的大小,所以它应该在恢复后返回到它的早期大小。我想这可能是一个错误。所以我想知道如何避免这种情况。我的想法是捕获恢复事件,然后将表单大小更改为应该的大小,但我不知道如何捕获恢复事件。

1 个答案:

答案 0 :(得分:1)

您可以通过覆盖WndProc执行此操作:

 protected override void WndProc( ref Message m )
    {
        if( m.Msg == 0x0112 ) // WM_SYSCOMMAND
        {
            // Check your window state here
            if (m.WParam == new IntPtr( 0xF120) ) // Maximize event - SC_MAXIMIZE from Winuser.h
            {
                  // THe window is being restored
                  this.Size = ActiveMdiChild.Size;
                  this.Height +=150;
            }
        }
相关问题