locked
Windows From top right corner buttons (c#) RRS feed

  • Question

  • Hi
    my windows form, there is a small "x" button on the top right corner
    i want to add something to it when it is clicked
    but i amnot sure where i can access it

    just went through the event list of the from
    didn't see anything i want. (i could miss some)
    Tuesday, April 1, 2008 1:59 PM

Answers

  • please follow this MSDN sample code.

    private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
       // Determine if text has changed in the textbox by comparing to original text.
       if (textBox1.Text != strMyOriginalText)
       {
          // Display a MsgBox asking the user to save changes or abort.
          if(MessageBox.Show("Do you want to save changes to your text?", "My Application",
             MessageBoxButtons.YesNo) ==  DialogResult.Yes)
          {
             // Cancel the Closing event from closing the form.
             e.Cancel = true;
             // Call method to save file...
          }
       }
    }

     Coop Developer wrote:
    actually that didn't solve my problem because when user clicks on the "x" button, i am actually asking for confirmation, but when user clicks "no", it exists anyway

    so i don't think that is the event i want.
    Tuesday, April 1, 2008 3:06 PM

All replies

  • try form_closing event.

     

     Coop Developer wrote:
    Hi
    my windows form, there is a small "x" button on the top right corner
    i want to add something to it when it is clicked
    but i amnot sure where i can access it

    just went through the event list of the from
    didn't see anything i want. (i could miss some)

    Tuesday, April 1, 2008 2:08 PM
  • thanks worked like a charm.
    Tuesday, April 1, 2008 2:24 PM
  • actually that didn't solve my problem because when user clicks on the "x" button, i am actually asking for confirmation, but when user clicks "no", it exists anyway

    so i don't think that is the event i want.
    Tuesday, April 1, 2008 3:00 PM
  • please follow this MSDN sample code.

    private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
       // Determine if text has changed in the textbox by comparing to original text.
       if (textBox1.Text != strMyOriginalText)
       {
          // Display a MsgBox asking the user to save changes or abort.
          if(MessageBox.Show("Do you want to save changes to your text?", "My Application",
             MessageBoxButtons.YesNo) ==  DialogResult.Yes)
          {
             // Cancel the Closing event from closing the form.
             e.Cancel = true;
             // Call method to save file...
          }
       }
    }

     Coop Developer wrote:
    actually that didn't solve my problem because when user clicks on the "x" button, i am actually asking for confirmation, but when user clicks "no", it exists anyway

    so i don't think that is the event i want.
    Tuesday, April 1, 2008 3:06 PM