I want to avoid my child form from appearing many times when a user tries to open the child form which is already open in MDIParent. One way to avoid this is by disabling the Controller (in my case BUTTON) but I have given a shortcut key (Ctrl+L) for this function as well. So if the user types Ctrl+L, the same child Form opens and I can see two child forms are in MDI.
private void leadsToolStripMenuItem_Click(object sender, EventArgs e)
{
frmWebLeads formWeblead = new frmWebLeads();
formWeblead.MdiParent = this;
formWeblead.WindowState = System.Windows.Forms.FormWindowState.Maximized;
formWeblead.Show();
}
I want to avoid this. How can I do this?
In the image you can see that a child form Name Online Leads is opened twice as the user opened first time using Menu (LEADS) and second time by Shortcut key. I don't want this to happen. If the form is already opened it should avoid opening another same form ... How to do this?
the way i usually do it if i am only supposed to have one open is something like:
//class member for the only formWeblead
frmWebLeads formWebLead = null;
private void leadsToolStripMenuItem_Click(object sender, EventArgs e)
{
if (formWebLead == null)
{
formWeblead = new frmWebLeads();
formWeblead.MdiParent = this;
}
formWeblead.WindowState = System.Windows.Forms.FormWindowState.Maximized;
formWeblead.Show();
}
Set this in your form main() function
InitializeComponent();
this.WindowState = FormWindowState.Maximized;
this.ShowInTaskbar = true;
from_login login = new from_login();
login.MdiParent=this;
login.Show();
pmsnrr.pmsmain = this;
and this is the code the goes inside your menu strip slick event
if (this.ActiveMdiChild != null)
this.ActiveMdiChild.Close();
frm_companymaster company = new frm_companymaster();
company.MdiParent = this;
company.WindowState = FormWindowState.Normal;
company.Show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With