First of all, I want to clarify that similar questions like this, is already asked in stackoverflow but none of those solved my problem. So, before you mark my questions as a duplicate, please understand my problem first.
I have two form
named frmNewCustomer
and frmCustomers
. Inside frmCustomers
I have a button
control named btnNewCustomer
that opens frmNewCustomer
whenever I click the button
. These two forms are MdiChildren
of another form named WMS
. Now, I don't want to open a form
if it is already opened. For that what I have done is this (Code for frmCustomers
).
namespace WMS.Presentation
{
public partial class frmCustomers : Form
{
Form newCustomer = new frmNewCustomer();
public frmCustomers()
{
InitializeComponent();
}
private void btnNewCustomer_Click(object sender, EventArgs e)
{
if (newCustomer.IsDisposed)
newCustomer = new frmNewCustomer();
newCustomer.MdiParent = this.MdiParent;
newCustomer.Show();
newCustomer.BringToFront();
}
}
}
Now suppose, I opened the form frmCustomers
from the main form (Form1)
menu. After that I clicked the button btnNewCustomer
. So, I have to form
opened now inside Form1
. If I again click on the file menu of Form1
and try to open frmCustomers
it doesn't open a new form, it just focus
on the opened instance of frmCustomers
which is fine. This way I can focus
on frmNewCustomers
too.
Now, If I close frmCustomers
while frmNewCustomer
is opened then again open frmCustomers
and try to focus
on the opened frmNewCustomers
by clicking btnNewCustomer
it doesn't work. It opens a new frmNewCustomer
which I don't want. I just simply want to focus on the opened instance of frmNewCustomer
. What can I do to solve my problem? I am enclosing a screenshot so you may have better understanding of my problem.