Is there an easy method to restore a minimized form to its previous state, either Normal or Maximized? I'm expecting the same functionality as clicking the taskbar (or right-clicking and choosing restore).
So far, I have this, but if the form was previously maximized, it still comes back as a normal window.
if (docView.WindowState == FormWindowState.Minimized) docView.WindowState = FormWindowState.Normal;
Do I have to handle the state change in the form to remember the previous state?
I use the following extension method:
using System.Runtime.InteropServices; namespace System.Windows.Forms { public static class Extensions { [DllImport( "user32.dll" )] private static extern int ShowWindow( IntPtr hWnd, uint Msg ); private const uint SW_RESTORE = 0x09; public static void Restore( this Form form ) { if (form.WindowState == FormWindowState.Minimized) { ShowWindow(form.Handle, SW_RESTORE); } } } }
Then call form.Restore()
in my code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With