c# – 无法访问已处置的对象错误
发布时间:2020-12-15 04:00:19  所属栏目:百科  来源:网络整理 
            导读:我收到错误消息无法访问已处理的对象. 对象名称:’ApplicationProperties’.当我在关闭它后重新打开一个表单.我注意到这是从退出的表单,退出是“处理”他们,所以我把所有的接受按钮和取消按钮(任何关闭窗体的按钮)下面的代码. this.Hide(); this.Parent = n
                
                
                
            | 我收到错误消息无法访问已处理的对象. 
  对象名称:’ApplicationProperties’.当我在关闭它后重新打开一个表单.我注意到这是从退出的表单,退出是“处理”他们,所以我把所有的接受按钮和取消按钮(任何关闭窗体的按钮)下面的代码. this.Hide(); this.Parent = null; 这段代码只是隐藏窗体.不关闭表单. 所以我的问题是,当我点击表单上的“x”按钮,然后尝试重新打开窗体,我仍然收到错误消息.我已经尝试了几个不同的方式修改形式的退出函数,如: private void ApplicationProperties_FormClosing(object sender,FormClosingEventArgs e)
    {
        //Hiding the window,because closing it makes the window unaccessible.
        this.Hide();
        this.Parent = null;
    }但这没有给我带来运气.我想知道有没有人知道如何解决这个问题.这是在我的取消和接受按钮内为我工作的代码.对于关闭表单的所有按钮,都是一样的. private void OptionsCancelbtn_Click(object sender,EventArgs e)
    {
        //Hiding the window,because closing it makes the window unaccessible.
        this.Hide();
        this.Parent = null;
    }我已经在Form1的顶部声明了这个实例,并且在form1中有一个打开form2的按钮. public partial class MainBox : Form
{
    //Making a name for the ApplicationProperties form. It can be opened when called.
    ApplicationProperties ApplicationPropertiesWindow = new ApplicationProperties();
    private void ApplicationPropertiesbtn_Click(object sender,EventArgs e)
    {
        //Show the properties window.
        ApplicationPropertiesWindow.Show();
    }//End ApplicationProperties button.
 }在我使用第二个窗体上的’x’按钮关闭程序后,由于ApplicationPropertiesWindow.Show()中的错误信息触发,我再也无法访问form2. 里面的form2我有以下代码: public partial class ApplicationProperties : Form
{
    //Creates and sets the instance MainBoxWindow.
    public MainBox MainBoxWindow { get; set; }解决方法
 在FormClosing事件中尝试这样做: 
  
  
  private void ApplicationProperties_FormClosing(object sender,FormClosingEventArgs e)
  {
        //Hiding the window,because closing it makes the window unaccessible.
        this.Hide();
        this.Parent = null;
        e.Cancel = true; //hides the form,cancels closing event
   }导致现在还在关闭窗体,从而仍然导致错误. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! | 
推荐文章
            站长推荐
            
        热点阅读
            