Hi guys,
as i'm coding for learning the three methods, i found an interesting thing:
The programm is:
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
System::Windows::Forms::DialogResult result1;
result1= MessageBox::Show("sure to quit?", "", MessageBoxButtons::YesNo, MessageBoxIcon::Question);
if(result1==System::Windows::Forms::DialogResult::Yes)
{
Application::Exit();
}
}
private: System::Void Form1_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e) {
System::Windows::Forms::DialogResult result2;
result2= MessageBox::Show("sure to quit?", "", MessageBoxButtons::YesNo, MessageBoxIcon::Question);
if(result2==System::Windows::Forms::DialogResult::Yes)
{
e->Cancel=false;
}
else
{e->Cancel=true;}
}
Also, what i wanna my prog to do is:
1. when button2 is clicked, show a messagebox to ask the user if he really wants to quit.
2. when "X" is clicked, show a messagebox to ask the user if he really wants to quit.
Problem:
You need to click twice "yes" to leave the form by situation1(button2). But if i cancel the situation 2, the "Application::Exit()" works well.
Why this happens? Could you experts explain? I don't need msdn links for Exit(), ExitThread() and Close() because i've read them more than 10 times. Maybe i didn't understand them. If so, please explain where is the point.
Thanks a lot!