0

Being a very first user in Windows Form Development I want to ask a simple question ...

I created a form(MainWindow.cs) within the solution which opens at the time of running that solution.

Latter I created a second form(SecondWindow.cs) and created a event so that it can be called from the first window by clicking a button.When the second window loded up the first window(MainWindow.cs) will be disabled.

Now I want to enable the MainWindow.cs when the second window is closed.

How to do That...

A simple solution I already have is to hide the MainWindow.cs and latter on closing the second window make a new object of first window and show it.But it is not a good way i think because there is already a object created by .net framework for first window automatically, so why we should create a new object of Mainwindow.cs .

Code Of First Window ( MainWindow.cs ) :

private void priceControllToolStripMenuItem_Click(object sender, EventArgs e)
    {
       SecondWindow price = new SecondWindow();
        this.Enabled = false;
        price.Show();
    }

Code Of Second Window ( On closing SecondWindow.cs )

private void price_controll_FormClosed(object sender, FormClosedEventArgs e)
    {
        // what will goes here to make the MainWindow.cs to enable state
    }
4

2 回答 2

2

用于price.ShowDialog()将第二种形式显示为模式对话框。主窗体将被禁用,直到您关闭第二个窗体:

private void priceControllToolStripMenuItem_Click(object sender, EventArgs e)
{
    using(SecondWindow price = new SecondWindow())
        price.ShowDialog();
}
于 2013-07-21T18:22:29.197 回答
0

您可以将主表单作为所有者传递给第二个表单

private void priceControllToolStripMenuItem_Click(object sender, EventArgs e)
{
    SecondWindow price = new SecondWindow() { Owner = this };
    this.Enabled = false;
    price.Show();
}

然后你可以从第二种形式中引用它。

private void price_controll_FormClosed(object sender, FormClosedEventArgs e)
{
    Owner.Enabled = true;
}
于 2013-07-21T18:42:19.177 回答