我收到错误消息无法访问已处置的对象。对象名称:“应用程序属性”。当我在关闭表单后尝试重新打开表单时。我注意到这是来自退出表单,退出是它们的“处理”,因此我将以下代码放入所有接受按钮和取消按钮(关闭表单的任何按钮)中。
 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”按钮关闭程序后,我无法再次访问 form2,因为在ApplicationPropertiesWindow.Show();
在 form2 我有以下代码:
public partial class ApplicationProperties : Form
{
    //Creates and sets the instance MainBoxWindow.
    public MainBox MainBoxWindow { get; set; }