andree
andree

Reputation: 3234

Problem with Form size after Restore event

I have a Mdi application with 1 Parent form and 3 Child forms. Parent Form size is always calculated like this:

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

Problem is, when I minimize Parent Form, and then restore it, its size after restore has decreased by 20. So the form looks kinda distorted. In my code, I haven't specified it to decrese it's size so it should return to it's earlier size after restore. I guess it could be a bug. So I was wondersing how I could avoid this. My idea was to catch the restore event, and then change form size to what it should be, but I don't know how to catch restore event.

Upvotes: 0

Views: 612

Answers (1)

Marshal
Marshal

Reputation: 6671

You can do this by overriding 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;
            }
        }

Upvotes: 1

Related Questions