Wednesday, April 20, 2016

Close all other instances of window form when open new one through menustrip item click

Write method in MDIPatent form :-
---------------------------------------------

private void CheckActiveChildForm(Form FormControl, string FormExists)
        {
            int h = 0;
            if (MdiChildren.Count() == 0)
            {
                //Form2 childF = new Form2();
                FormControl.MdiParent = this;
                FormControl.Show();
            }
            if (MdiChildren.Count() > 0)
            {
                for (int i = 0; i < MdiChildren.Count(); i++)
                {
                    if (MdiChildren.ElementAt(i).Text != FormExists)
                    {
                        h = 1;
                        MdiChildren.ElementAt(i).Close();
                    }
                }
            }


            if (h == 1)
            {
                FormControl.MdiParent = this;
                FormControl.Show();
            }
        }

Call method on menu strip menu item event :-
-----------------------------------------------------------

 Job frmJob = new Job();
            CheckActiveChildForm(frmJob, "Add/Edit Job");

Here : "Add/Edit Job" is the form text which is to be pass as a paremeter.

1 comment:

  1. 7 best casinos where you can play online slots with no download and no
    This casino is a good place to find games 온라인 바카라 사이트 and live dealer games. You'll see 비트 코인 게임 that 램 슬롯 many games are available in this 이스포츠 casino. 부들이벗방

    ReplyDelete