Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
public ref class form3 : public System::Windows::Forms::Form
{
public:
    form3(void)
    {
    	InitializeComponent();
    	timer1->Start();
    	//
    	//TODO: Add the constructor code here
    	//
    }
    
protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~form3()
    {
    	if (components)
    	{
    		delete components;
    	}
    }

private: 
    System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e)
    {
        DateTime datetime = DateTime::Now;
        this->label1->Text=datetime.ToString();
    }

    System::Void form3_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e)
    {
        if (MessageBox::Show("Do you Really Want to Exit?","Form3", MessageBoxButtons::YesNo,MessageBoxIcon::Question) == (System::Windows::Forms::DialogResult::Yes))
        {
            timer1->Stop();      //i enabled timer
            //Application::Exit();
            form3::Close();	
        }
        else
        {
            e->Cancel=true;
        }
    }	
}

Here in this code,When i click "X" button on form ,it is asking to close or not,but Even though i choose 'yes'option, dialog box is not closing.
Posted
Updated 15-Sep-14 4:21am
v3

1 solution

Have you put a break point on this line
C++
if (MessageBox::Show("Do you Really Want to Exit?","Form3", ...

to see if your code is executed?

You can try to change
C++
form3::Close();	

to
C++
this->Close();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900