Minimize/Restore with hidden caption bar makes window shrink/grow

Topics: Developer Forum
Dec 21, 2006 at 8:37 AM
First of all. I just downloaded the source and do not know if this issue has been up here before. But anyhow. Here I go:

How to reproduce:

Im running XP SP2 - classic mode...

1) I downloaded version 6125 of the source code.
2) Start the Demo sample.
3) Check the "Enable custom borders" checkbox.
4) Minimize the Demo window
5) Restore the Demo window

After restoring the window, it's height has increased (compared to when it was minimized).

Excpected behaviour:
The window should have the same size after it has been restored as it had before being minimized.

The same behaviour exists when the following is done:
1) "Show desktop" (WinD or WinM)
2) Restore the Demo window.

I now that the same windows messages are not sent in this case compared to the above, but it should behave the same way.
Aug 7, 2007 at 12:13 PM
Hi, were you able to solve this problem?
Apr 22, 2008 at 7:17 AM
The same problem exist for all custom drawn forms (my own also) . May be the author of this code fix the problem.
The minimize restore problem exist if height of the caption (by changing client area) is changed. If it is kept as the standard OS height you will not get this issue.
Nov 12, 2009 at 4:09 PM

My solution, sparked by Justin Rogers Awesome Windows Forms message pump trick:

    private delegate void VoidMethodInvoker();
    public void ShrinkWindow()
        int widthAdjust = 2 * SystemInformation.BorderSize.Height;
        int heightAdjust = SystemInformation.CaptionHeight + 2 * SystemInformation.BorderSize.Height;
        this.Size = new System.Drawing.Size(Size.Width - widthAdjust, Size.Height - heightAdjust);

// Then in the Resize event:
     case FormWindowState.Normal:
            this.BeginInvoke(new VoidMethodInvoker(this.ShrinkWindow));


The BeginInvoke puts the ShrinkWindow call on the message pump; calling it directly from within the Resize event handler is too early 
and the ResizeEnd event doesn't seem to fire when the caption bar is not visible.  The end user does see this grow and shrink, but it's 
pretty quick.


Feb 18, 2014 at 8:08 PM
Edited Feb 18, 2014 at 8:09 PM
I solved it using this answer

User doesn't see anything using this.

You can see my source here