How to pass a form name to a sub program
-
Hi All, I am new to C# and OOP. I refered a article about Single instance child for in MDIhttp://www.codeproject.com/csharp/single_instance.asp?df=100&forumid=51798&select=1394073#xx1394073xx[^]) I tried to write a sub program to stop that code duplication as follows
private void frmLoad(Form frmNew) { Form[] charr = this.MdiChildren; if (charr.Length == 0) // no child form is opened { frmNew sus = new frmNew(); sus.MdiParent = this; sus.StartPosition = FormStartPosition.Manual; sus.Location = new Point(0, 0); sus.Show(); } else // child forms are opened { int count = 0; foreach (Form chform in charr) { if (chform.Name == "frmNew")// one instance of the form is opened { chform.Activate(); count = 0; break; // exit loop } else count++; } if (count > 0) { frmNew sus = new frmNew(); sus.MdiParent = this; sus.StartPosition = FormStartPosition.Manual; sus.Location = new Point(0, 0); sus.Show(); } } }
I want to pass a form name as a argument. what is wrong with this? Please can anybody help me?:(( mWith -
Hi All, I am new to C# and OOP. I refered a article about Single instance child for in MDIhttp://www.codeproject.com/csharp/single_instance.asp?df=100&forumid=51798&select=1394073#xx1394073xx[^]) I tried to write a sub program to stop that code duplication as follows
private void frmLoad(Form frmNew) { Form[] charr = this.MdiChildren; if (charr.Length == 0) // no child form is opened { frmNew sus = new frmNew(); sus.MdiParent = this; sus.StartPosition = FormStartPosition.Manual; sus.Location = new Point(0, 0); sus.Show(); } else // child forms are opened { int count = 0; foreach (Form chform in charr) { if (chform.Name == "frmNew")// one instance of the form is opened { chform.Activate(); count = 0; break; // exit loop } else count++; } if (count > 0) { frmNew sus = new frmNew(); sus.MdiParent = this; sus.StartPosition = FormStartPosition.Manual; sus.Location = new Point(0, 0); sus.Show(); } } }
I want to pass a form name as a argument. what is wrong with this? Please can anybody help me?:(( mWithJust create a member variable for frmNew:
private Form2 frmNew = null;
private void CreateFrmNew()
{
if (frmNew == null)
{
frmNew = new Form2();
frmNew.MdiParent = this;
frmNew.StartPosition = FormStartPosition.Manual;
frmNew.Location = new Point(0, 0);
}frmNew.Show();
}Call CreateFrmNew, it will create frmNew if not exists, otherwise frmNew will be shown.