Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

minimize window when user presses 'x'

Status
Not open for further replies.

dky1e

Programmer
May 4, 2002
293
US
Hi,

I want to minimize the window when a user clicks the 'x' button in the control box on top of the window.

How can I prevent the window from closing?
thanks...
 
try disabling the x button and enabling the min and max buttons of the controlbox
 
I found a solution by overriding the IsClosing method.

[tt]
protected override void OnClosing( System.ComponentModel.CancelEventArgs e )
{
//cancels the closing event
e.Cancel = true;
//hides the window
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Hide ();

}
[/tt]

Is this good enough?
 
dky1e -

That sounds pretty good to me. Does it also work with the context menu (left-click on window's icon), and with the keyboard shortcut (alt-f4) ?

Chip H.
 
Looks good to me too, but at this point I have a question for you:
- Why would you change a procedure to do something that it was not planned to do and something that is done by another procedure??
Looks like you are trying to make the Add procedure subtract two numbers instead of adding them...

I'm just curious

If you are just trying to disable the user option of closing an application then the "canonic way" would be to diable the X button from the control box

*my two cents*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top