Search code examples
c#windowstate

How do I trigger something whenever the WindowState changes in C#?


So I want to instantly, as this portion of the program relies on speed, trigger a function when the windowstate is changed in my main form. I need it to be something like this:

private void goButton_Click(object sender, EventArgs e)
{
   //Code
}

I checked through the events tab of the form, I have no WindowStateChanged, etc. How do I do this?

The form will be resized a lot, so checking when the size changes won't work.


Solution

  • The Resize event (or SizeChanged) will fire when the WindowState changes.


    On a side note, WPF does include a StateChanged event for this directly.