Nov 12, 2011

Check if a form is open in an MDI container?

  1. //see if the form is already open, if it is, set focus to it, if not, open it
  2. foreach (Form a in MdiChildren)
  3. {
  4. if (a is frmEditorAccounts)
  5. {
  6. //the form is open, set focus to it
  7. a.BringToFront();
  8. a.Activate();
  9. break;
  10. }
  11. }
  12. if (ActiveMdiChild == null || ActiveMdiChild.Name != "frmEditorAccounts")
  13. {
  14. //no forms are open
  15. //open one
  16. frmEditorAccounts Accounts = new frmEditorAccounts();
  17. Accounts.MdiParent = this;
  18. Accounts.Show();
  19. }

0 comments:

Post a Comment

Nam Le © 2014 - Designed by Templateism.com, Distributed By Templatelib