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. Check if open is already open

Check if open is already open

Scheduled Pinned Locked Moved C#
tutorial
9 Posts 6 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.
  • S Offline
    S Offline
    soneliso
    wrote on last edited by
    #1

    How to check if the form is already open, so that it cannot be duplicatly openned

    F A A 3 Replies Last reply
    0
    • S soneliso

      How to check if the form is already open, so that it cannot be duplicatly openned

      F Offline
      F Offline
      fang_eric
      wrote on last edited by
      #2

      do it with the form load event that like this: if (Process.GetProcessesByName(yourprocessname).Length >=1){ MessageBox.show("already opened!"); return; }

      G S N 3 Replies Last reply
      0
      • F fang_eric

        do it with the form load event that like this: if (Process.GetProcessesByName(yourprocessname).Length >=1){ MessageBox.show("already opened!"); return; }

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        I think he meant some form he has in his application, not the application itself

        F S 2 Replies Last reply
        0
        • G Giorgi Dalakishvili

          I think he meant some form he has in his application, not the application itself

          F Offline
          F Offline
          fang_eric
          wrote on last edited by
          #4

          if that is like you said, that needs to use Mutex.

          1 Reply Last reply
          0
          • F fang_eric

            do it with the form load event that like this: if (Process.GetProcessesByName(yourprocessname).Length >=1){ MessageBox.show("already opened!"); return; }

            S Offline
            S Offline
            soneliso
            wrote on last edited by
            #5

            Thanks but my problem i want to close form1 before opening form2

            1 Reply Last reply
            0
            • G Giorgi Dalakishvili

              I think he meant some form he has in his application, not the application itself

              S Offline
              S Offline
              soneliso
              wrote on last edited by
              #6

              Yes is like that

              1 Reply Last reply
              0
              • F fang_eric

                do it with the form load event that like this: if (Process.GetProcessesByName(yourprocessname).Length >=1){ MessageBox.show("already opened!"); return; }

                N Offline
                N Offline
                Nouman Bhatti
                wrote on last edited by
                #7

                Use singleton design pattern and it'll solve your problem for example u want form1 to be checked if it's already opened take a object of form1 with in your form1 class make the constructor private of your form1 class make a public static method with in that method check if the object is null or not if null assign a new instance of your form1 and if not null then return the already initialized instance

                1 Reply Last reply
                0
                • S soneliso

                  How to check if the form is already open, so that it cannot be duplicatly openned

                  A Offline
                  A Offline
                  Aron Miserda
                  wrote on last edited by
                  #8

                  Best way to solve this is to to make your class constructor private and put static method that returns reference to only instance of your class Code example: class Example { private static Example THIS = null; public static Example CREATE_FORM() { if (THIS == null) THIS = new Example(); return THIS; } private Example() { } }

                  1 Reply Last reply
                  0
                  • S soneliso

                    How to check if the form is already open, so that it cannot be duplicatly openned

                    A Offline
                    A Offline
                    AFSEKI
                    wrote on last edited by
                    #9

                    if( myForm != null && !myForm.Disposing && myForm.IsHandleCreated) return; else myForm.Show();

                    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