Introduction
private void button1_Click(object sender, EventArgs e)
{
bool IsOpen = false;
foreach (Form f in Application.OpenForms)
if (f.Text == "Form2")
IsOpen = true;
f.Focus();
break;
}
if (IsOpen == false)
Form2 f2 = new Form2();
f2.MdiParent = this;
f2.Show();
Hi Kirtan,Thanks for putting the code snippet here. It saved me some time on researching.But I feel, using the name property of form instead of text is a a better solution.E.g.if (f.Text == "Form2") --> if (f.Name == "Form2")Thanks again. :)
if (f.Text == "Form2") --> if (f.Name == "Form2")Thanks again. :)
How to Prevent Multiple Instances of Child Form in MDI Windows Form Application
Counting Words in C#
Thanks for article it was very helpful to me.
Hi, Thanks for your article, it helps me in some issue with simple idea, which gets me trouble for long.. I have little bit of confussion on remoting concept in programming. Plz..Can u provide me sample as well as realtime application with Remoting I'm looking for your response... to this mail "pavanpabolu@gmail.com" plzzz thanks pavan
in my application i am opening child forms by clicking on menu strip items.when i follow ur code ,i prevent opening multiple instances,but everytime i choose a different menu item,the old form is minimized..how can i prevent that??!i am new to C# corner..i dont know if i am going to get an answer...thanx
hello,if i want to use this code in a function that i would call from each onClick instance that would send that function the form name or the form requested,so that i don't repeat the code for all button clicks and form requests,how would the code change? ...my problem is in this part : Form2 f2 = new Form2(); if i send the form name or the form itself, in what way can i create a new instance in the function ??public void checkIfOpen(Form thisForm) { bool IsOpen = false; foreach (Form f in Application.OpenForms) { if (f.Name == thisForm.Name ) { IsOpen = true; f.Focus(); break; } } if (IsOpen == false) { what to do here ?? thisForm f2 = new thisForm(); f2.Show(); } }
in what way can i create a new instance in the function ??public void checkIfOpen(Form thisForm) { bool IsOpen = false; foreach (Form f in Application.OpenForms) { if (f.Name == thisForm.Name ) { IsOpen = true; f.Focus(); break; } } if (IsOpen == false) { what to do here ?? thisForm f2 = new thisForm(); f2.Show(); } }
Hi Kirtan,Thanks for putting the code snippet here. It saved me time on research.But I would suggest that you go for the Name property of form instead of Text property, that is a bit better solution.if (f.Text == "Form2") -> if (f.Name == "Form2")Thanks again :)
if (f.Text == "Form2") -> if (f.Name == "Form2")Thanks again :)