Berkil Posted October 14, 2009 Posted October 14, 2009 Hello My origional goal was to override the X button, so instead of closing it would minimize to the task bar. I reached my goal by using the following code: private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { this.Hide(); e.Cancel = true; } Now the only way the program could be closed was by pressing the 'Close' menu item. private void closeToolStripMenuItem_Click(object sender, EventArgs e) { Close(); Application.Exit(); } This just opens a new issue: I CAN'T SHUT DOWN MY COMPUTER!!!. While the program is running (on a windows XP machine) the machine wouldn't shut down. It would be much appriciated if someone could tell me another way to override the X button or just some other way to solve my problem :P Quote
Administrators PlausiblyDamp Posted October 14, 2009 Administrators Posted October 14, 2009 In the closing event you can check e.CloseReason to discover why your application is trying to close, simply decide which should and should not block the exit. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Berkil Posted October 14, 2009 Author Posted October 14, 2009 hmm, could you give me an example. I don't see how or where i should put this in my code :P.. the code name.CloseReason only works with FormClosingEventArgs. How do i mix it :P Quote
Berkil Posted October 14, 2009 Author Posted October 14, 2009 (edited) Nevermind, i figured it out. Thank you very much. If you see any flaw in my result please say so :P private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { e.Cancel = true; Hide(); } else { Close(); Application.Exit(); } } Isn't it weird that it's only machines running XP, who encounter this error ?. Edited October 14, 2009 by Berkil Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.