Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted
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
Posted (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 by Berkil

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...