Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can we open only one instance of a form at a time from a MDIparent form in C#.net

How can we open only one instance of a form at a time from a MDIparent form in C#.net

Scheduled Pinned Locked Moved C#
csharp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anu Palavila
    wrote on last edited by
    #1

    Hai All, How can we open only one instance of a form at a time from a MDIparent form in C#.net Thanks & Regards

    I D 2 Replies Last reply
    0
    • A Anu Palavila

      Hai All, How can we open only one instance of a form at a time from a MDIparent form in C#.net Thanks & Regards

      I Offline
      I Offline
      imsathy
      wrote on last edited by
      #2

      this condition on Form1 would ensure that there's only one copy in the existence if(obj == null || obj.IsDisposed) { obj = new Form2(); obj.Show(); }

      Sathy

      1 Reply Last reply
      0
      • A Anu Palavila

        Hai All, How can we open only one instance of a form at a time from a MDIparent form in C#.net Thanks & Regards

        D Offline
        D Offline
        darkelv
        wrote on last edited by
        #3

        You can do that by having a "manager" class that manage the child form. 1. Caller call a method in the manager, given the type of the form that you want to open. 2. Manager check MdiChildren of that type, if it finds it, return the form object back to caller. 3. If manager not able to find it, then create a new instance via reflection, then return back to caller. 4. Caller receive the form, do necessary action on the form (pass object, show, etc) You can mix it up a bit by having some form can only be opened as 1 instance, while other form can be opened multiple time, by adding customattribute to the form class or adding an "AllowMultiple" via subclassing Form. This is by no means the only way.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups