4
Please Download the sample application attached here.
Hopefully that will solve your problem.
3
Friend,
Write Code like Below to Open the Form
it will Open The new Form if form is not open and if its Open then it will not open New Form Instead it will Focus the Opened Form
private void button1_Click(object sender, EventArgs e)
{
FormCollection fc = Application.OpenForms;
bool FormFound = false;
foreach (Form frm in fc)
{
if (frm.Name == "Form2")
{
frm.Focus();
FormFound = true;
}
}
if (FormFound == false)
{
Form2 f = new Form2();
f.Show();
}
}
All the Best
and
Check "Do you like this answer" please :)
0
Thanks Bosss... I Was very worried about this.... thanks for your code
0
use
forminstance.ShowDialog();
0
Hi dude.........
I m gaurav.......new to vb.net.........i need your help....you have given a code for mdi form for open only one instance of a form if it is already opened than the same is focused back.....and the code is in C # which is given below can you give me code for vb.net also.....and whr should i write this code in every form code or in form load..........
Please reply me on g_gumber@yahoo.com
private void button1_Click(object sender, EventArgs e)
{
FormCollection fc = Application.OpenForms;
bool FormFound = false;
foreach (Form frm in fc)
{
if (frm.Name == "Form2")
{
frm.Focus();
FormFound = true;
}
}
if (FormFound == false)
{
Form2 f = new Form2();
f.Show();
}
}
And i need one more help.........when we search data from database on the base of Id which is primary key.........we can show this data in datagridview........but i want to export same result in excel format..........how can i do can send me a sample code.....
Thanks
Gaurav Gumber
g_gumber@yahoo.com
0
Thank you Kirtan!
Nice and simple and works!
0
U can close using following code
Form activeform_inapp = this.ActiveMdiChild;
if (activeform_inapp == null)
{
}
else
{
activeform_inapp.Close();
}
regards,
minakshi
0
The following code is used to close all the MDI child forms
foreach (Form aFormL in this.OwnedForms)
{
aFormL.Close();
}
0
See bellow code to open only one instance of the form
public partial class Form2 : Form
{
Form1 aFormL;
Form3 aForm3L;
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (aFormL == null)
{
aFormL = new Form1();
aFormL.Show();
}
}
private void button2_Click(object sender, EventArgs e)
{
if (aForm3L == null)
{
aForm3L= new Form3();
aForm3L.Show();
}
}
}
0
Sorry, but i am able to implement the given code snippet.
Can u please give it in detail.
Do u know how to close all opened child windows in MDI form, it can also work in my problem.
Regards,
Vidya
0
declare aFormL as member of the form(to access public)
Form1 aFormL;
in the button click
do as follows
if (aFormL == null)
{
aFormL = new Form1();
aFormL.Show();
}
0
Thanks,
But this now don't allow me to open any other forms also.
Means more presicesly i don't want to open duplicate forms.
If Form1 is opened once then it should not be opened again but, we must be able to open Form2 aslo along with Form1.
Can u help me on this problem, it's urgent,
Regards,
Vidya
0
When you open the form from the MDI form...
use the ShowDialog()
Following is the sample code
Form1 aFormL = new Form1();
aFormL.ShowDialog();
Form2 aFormL = new Form2();
aFormL.ShowDialog();
So you can open only one form at the time