Trapping windows app minimize functionality
-
Hi all, Can anyone tell me how I can trap the event of minimizing and closing a C# windows appliction? I'm only referring to when the user hits the minimize or close button on the form's control box. I need to set a flag for my application to do something when this event occurs and I'm not sure how. Thanks ;)
-
Hi all, Can anyone tell me how I can trap the event of minimizing and closing a C# windows appliction? I'm only referring to when the user hits the minimize or close button on the form's control box. I need to set a flag for my application to do something when this event occurs and I'm not sure how. Thanks ;)
Regarding the closing event, you should use the OnClosing event handler:
private void Form2_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//TODO: Add custom code here
}As for the minimizing event, Windows Forms does not have a prefedined event that handles just the minimizing of the form but you can circumvent that by using the following code:
protected override void OnResize(EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
//TODO: Add custom code here
}}