Friday, 19 July 2013

Prevent Window form to Open when Same form Open Already

Try this code on Window(Form) Open Events it will close open form and open new form/window........

var form1 = new Formname();
                var openedForm = Application.OpenForms[form1.Name];
                if (openedForm != null)
                {
                    openedForm.WindowState = FormWindowState.Normal;
                    openedForm.BringToFront();
                    openedForm.Activate();
                }
                else
                {
                    // If required.
                    form1.MdiParent = this;
                    form1.Show();
                }

No comments:

Post a Comment