Problem/Glitch with Minimizing and Maximizing

Jan 7, 2011 at 12:33 AM


I've been using this ribbon for a couple of weeks now, and I've just noticed that everytime I minimize or maximize the form the ribbon is on, the height of the form increases by exactly 30 pixels upon returning the WindowState to normal.

I've tested this with many applications I've made switching between .net framework 3.5 and 4.0, and tested all the sample applications provided with the library, and this happens consistetly with all of them.

Is there any way to fix this so the normal WindowState size doesn't change after minimizing or maximizing??


Jan 7, 2011 at 9:39 PM

Just an update.

I noticed someone already mentioned this under Issue Tracker (  However, although the user "rasmusfoged" stated "Issues is solved with the work-around to use Win32 API for hiding the form in taskbar. See VB.NET code below:".  Their solution did not resolve the issue with the normal WindowState size increasing by 30pixels after minimizing or maximizing.  Additionally, I don't seem to experience any issue at all when the "showintaskbar" property is set to false.  Maybe I misunderstood...

Jan 10, 2011 at 5:53 PM
Edited Jan 10, 2011 at 5:54 PM

I think this is a Windows Forms bug in Form class. The Windows ribbon control changes the client area of the window and the resize fails. I hate to write such bad workarounds... Include the following code into your form and assign the SizeChanged event handler...

        FormWindowState _previousWindowState;
        int _previousNormalHeight;
        int _preserveHeight;

        private void Form1_SizeChanged(object sender, EventArgs e)
            this.label1.Text = this.Height.ToString();

            if (_previousWindowState != FormWindowState.Normal
                && this.WindowState == FormWindowState.Normal
                && _previousNormalHeight != 0)
                _preserveHeight = _previousNormalHeight;
                this.BeginInvoke(new MethodInvoker(RestoreHeight));

            if (this.WindowState == FormWindowState.Normal)
                _previousNormalHeight = this.Height;
            _previousWindowState = this.WindowState;

        void RestoreHeight()
            this.Height = _preserveHeight;
Jan 10, 2011 at 6:14 PM

Thanks a lot, bernhardelbl.  It works just fine.

Incase anyone needs it, here is the equivalent VB .Net code.

Private _previousWindowState As FormWindowState
Private _previousNormalHeight As Integer
Private _preserveHeight As Integer

Private Sub Form1_SizeChanged(sender As Object, e As EventArgs)
	Me.label1.Text = Me.Height.ToString()

	If _previousWindowState <> FormWindowState.Normal AndAlso Me.WindowState = FormWindowState.Normal AndAlso _previousNormalHeight <> 0 Then
		_preserveHeight = _previousNormalHeight
		Me.BeginInvoke(New MethodInvoker(AddressOf RestoreHeight))
	End If

	If Me.WindowState = FormWindowState.Normal Then
		_previousNormalHeight = Me.Height
	End If
	_previousWindowState = Me.WindowState
End Sub

Private Sub RestoreHeight()
	Me.Height = _preserveHeight
End Sub
Jan 10, 2011 at 6:26 PM

Great work Bernhard.

Jun 8, 2013 at 5:36 AM
I feel that this fix is a better work around as it doesn't mess with resetting the form size back - it merely ignores the size in the first place. Override WndProc in the form(s) that host the Ribbon control. You'll need a boolean field on the form and some native methods and consts, but you can fill in the blanks.
    protected override void WndProc( ref Message m )
        switch ( m.Msg )
        case NativeMethods.WM_WINDOWPOSCHANGING:
            Utils.NativeMethods.WINDOWPOS windowPos = 
                    ( Utils.NativeMethods.WINDOWPOS ) m.GetLParam( typeof( Utils.NativeMethods.WINDOWPOS ) );

            if ( this.WindowState == FormWindowState.Minimized )
                this._processNextWmPosChanging = true;

            if ( this._processNextWmPosChanging )
                this._processNextWmPosChanging = false;

                m.Result = IntPtr.Zero;
                windowPos.flags |= 0x1; /* SWP_NOSIZE */
                Marshal.StructureToPtr( windowPos, m.LParam, false );

            base.WndProc( ref m );