CloseButton

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Salim Zaabi
    New Member
    • Oct 2009
    • 25

    CloseButton

    Hi Everybody,

    How do I display a message when CloseButton on the form is clicked??
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    There is an event of .FormClosing.
    Attach your method to that.
    • Open the form in Designer.
    • On the Properties pallet click the events button (yellow lightening bolt)
    • Scroll down to FormClosing
    • Double-Click in the field to the right. A method stub will be created for you and an event handler will be created.
    • Put your message in that method


    Code:
            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                System.Windows.Forms.DialogResult result = MessageBox.Show("Are you sure", "Close?", MessageBoxButtons.YesNo,
                                                                           MessageBoxIcon.Question);
                if (result == System.Windows.Forms.DialogResult.No) e.Cancel = true; // Cancel the close
            }

    Comment

    • Salim Zaabi
      New Member
      • Oct 2009
      • 25

      #3
      tlhintoq

      Thanks my friend it works

      Comment

      Working...