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. Preventing multiple instances of the window

Preventing multiple instances of the window

Scheduled Pinned Locked Moved C#
helpquestion
9 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.
  • I Offline
    I Offline
    I explore code
    wrote on last edited by
    #1

    Hi guys, I need your help in preventing multiple instances of the same window from opening in an MDI parent child window application ? Its urgent ...thanks ...

    R A 2 Replies Last reply
    0
    • I I explore code

      Hi guys, I need your help in preventing multiple instances of the same window from opening in an MDI parent child window application ? Its urgent ...thanks ...

      R Offline
      R Offline
      RepliCrux
      wrote on last edited by
      #2

      What is the question, where are you stuck?

      I 2 Replies Last reply
      0
      • R RepliCrux

        What is the question, where are you stuck?

        I Offline
        I Offline
        I explore code
        wrote on last edited by
        #3

        My question is simple and straight..I want to prevent multiple instances of the same child window from opening i.e. only one instance of a window should open up when i select a certain menu option from the main menu. I hope i made myself clear this time..!!

        R 1 Reply Last reply
        0
        • I I explore code

          My question is simple and straight..I want to prevent multiple instances of the same child window from opening i.e. only one instance of a window should open up when i select a certain menu option from the main menu. I hope i made myself clear this time..!!

          R Offline
          R Offline
          RepliCrux
          wrote on last edited by
          #4

          One way can be: use frm.ShowDialog(); This way, unless you have not closed the current child form, you cannot open anyother. This might be a quick fix for your problem. If you don't want this you might have to google intensly :)

          I 1 Reply Last reply
          0
          • R RepliCrux

            One way can be: use frm.ShowDialog(); This way, unless you have not closed the current child form, you cannot open anyother. This might be a quick fix for your problem. If you don't want this you might have to google intensly :)

            I Offline
            I Offline
            I explore code
            wrote on last edited by
            #5

            yeah..I have tried that approach, but as u say, i was not able to to open up any other window until i closed this one..but tht should not happen in an MDI windows application ..right ? Can Dispose() method help in this case?

            1 Reply Last reply
            0
            • I I explore code

              Hi guys, I need your help in preventing multiple instances of the same window from opening in an MDI parent child window application ? Its urgent ...thanks ...

              A Offline
              A Offline
              andre_swnpl
              wrote on last edited by
              #6

              MDI Parent forms contain a collection of it's children (this.MdiChildren). Before you open a new instance of a form you could check this collection if your form exist and simply activate this instance.

              I 1 Reply Last reply
              0
              • R RepliCrux

                What is the question, where are you stuck?

                I Offline
                I Offline
                I explore code
                wrote on last edited by
                #7

                yeah..I have tried that approach, but as u say, i was not able to to open up any other window until i closed this one..but tht should not happen in an MDI windows application ..right ? Can Dispose() method help in this case?

                1 Reply Last reply
                0
                • A andre_swnpl

                  MDI Parent forms contain a collection of it's children (this.MdiChildren). Before you open a new instance of a form you could check this collection if your form exist and simply activate this instance.

                  I Offline
                  I Offline
                  I explore code
                  wrote on last edited by
                  #8

                  Can you elaborate a bit more...thanks

                  R 1 Reply Last reply
                  0
                  • I I explore code

                    Can you elaborate a bit more...thanks

                    R Offline
                    R Offline
                    RepliCrux
                    wrote on last edited by
                    #9

                    I found the solutions mate: Form2 frm = new Form2(); if (MdiChildren.Length != 0) { for (int i = 0; i < this.MdiChildren.Length; i++) { if (this.MdiChildren[i].GetType().Name != "Form2") { frm.Show(); frm.MdiParent = this; } } } else { frm.Show(); frm.MdiParent = this; } PS: you will have to modify this the above is real quick and dirty. You will have to check this for each and every form you open. Cheers.

                    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