我如何...通过询问用户是否关闭来关闭表单。 [英] How do I..can close the form by asking a user to cose or not.

查看:70
本文介绍了我如何...通过询问用户是否关闭来关闭表单。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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;
        }
    }	
}



在此代码中,当我单击表单上的X按钮时,它要求关闭或者没有,但即使我选择'是'选项,对话框也没有关闭。


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.

推荐答案

你在这条线上设置了断点

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



看你的代码是否被执行了?



你可以尝试改变


to see if your code is executed?

You can try to change

form3::Close();	



to


to

this->Close();


这篇关于我如何...通过询问用户是否关闭来关闭表单。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆