CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2002
    Posts
    121

    Intercept event for the 'x' button on window

    I want to minimize the window when a user clicks the 'x' button in the control box. How can I prevent the window from closing?
    thanks...

  2. #2
    Join Date
    May 2002
    Posts
    121
    ok.. I found a solution by overriding the OnClosing function:

    Code:
    protected override void OnClosing(  System.ComponentModel.CancelEventArgs e )
    		{
    			e.Cancel = true;
    			this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
    		}
    But I'm not sure if its enough, that is what happens when the program exits?

  3. #3
    Join Date
    Jun 2002
    Location
    Philadelphia, PA
    Posts
    85
    Have you tried hooking the public event, CancelEventHandler. According to the remarks from the documentation:

    The Closing event occurs as the form is being closed. When a form is closed, all resources created within the object are released and the form is disposed. If you cancel this event, the form remains opened. To cancel the closure of a form, set the Cancel property of the CancelEventArgs passed to your event handler to true.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured