1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

please help in C#

Discussion in 'C#' started by ahmedumar, Aug 27, 2007.

  1. ahmedumar

    ahmedumar New Member

    Joined:
    Aug 27, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hi, I have the following lines of code on the close event of the form. When the close button of the from clicks the messagebox appears, when i click "Yes", the application will close and when i click "No" the form will dissapear.please help me in making the form visible when i click "No".

    CODE:
    ------
    Code:
    protected override void OnClosing(CancelEventArgs e)
            {            
                DialogResult result;
                result=MessageBox.Show("On closing the application, you can loose any unsaved data! Do you want to continue?","close",MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    Application.Exit();
                    base.OnClosing(e);
                }
                else
                {
                }
            }
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    1
    Trophy Points:
    0
    You need to set the value of e for the dialog to remain as it is.
     
  3. nelsharp

    nelsharp New Member

    Joined:
    Oct 2, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    set e.Cancel = true; in the else part
     
  4. praspam

    praspam New Member

    Joined:
    Feb 22, 2012
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    if (!tYes)
    e.Cancel = true;
    else
    e.Cancel = false;
     

Share This Page