SoFunction
Updated on 2025-03-06

C# Implementation of WinForm Capture Minimization Events

Generally speaking, although the Form class does not provide Minimize events, WinForm capture minimization events can still be achieved by overloading Deactive.
The implementation method is: when Form loses focus, test WindowState to obtain Form status. If Minimized is a minimizing event.

This example is to hide the window after minimization:

There is another way to be more direct, overload WndProc:

The implementation code is as follows:

const int WM_SYSCOMMAND = 0x112;
const int SC_CLOSE = 0xF060;
const int SC_MINIMIZE = 0xF020;
const int SC_MAXIMIZE = 0xF030;
protected override void WndProc(ref Message m)
{
  if ( == WM_SYSCOMMAND)
  {
    if (.ToInt32() == SC_MINIMIZE)
    {
       = false;
      return;
    }
  }
  (ref m);
}

private void Form1_Deactivate(object sender, EventArgs e)
{
  if ( == )
  = false;
}

I hope that the examples described in this article will be helpful to everyone's C# programming.