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. Windows Forms
  4. how to limit the number of winform objects to one

how to limit the number of winform objects to one

Scheduled Pinned Locked Moved Windows Forms
tutorial
6 Posts 3 Posters 6 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.
  • J Offline
    J Offline
    John Robert Wilk
    wrote on last edited by
    #1

    I have a winform application that opens other winform objects I need to limit these new winform objects to one instance. I understand mutexes but don't know what to override in the winform object to limit it to a single instance.

    L M 2 Replies Last reply
    0
    • J John Robert Wilk

      I have a winform application that opens other winform objects I need to limit these new winform objects to one instance. I understand mutexes but don't know what to override in the winform object to limit it to a single instance.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      if it is all about forms in a single application, why can't you keep a count and organize things the way you want? I don't see the need for mutexes here. if it is about limiting the number of instances of a specific app, then that is where a mutex would come in. Search this site for "single instance application", you will find lots of articles (language doesn't matter, the principles are the same everywhere), some are good. BTW: none of them really limit the apps to one, all they do is have the extra instances close as soon as possible, however they do open first... :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      J 1 Reply Last reply
      0
      • L Luc Pattyn

        if it is all about forms in a single application, why can't you keep a count and organize things the way you want? I don't see the need for mutexes here. if it is about limiting the number of instances of a specific app, then that is where a mutex would come in. Search this site for "single instance application", you will find lots of articles (language doesn't matter, the principles are the same everywhere), some are good. BTW: none of them really limit the apps to one, all they do is have the extra instances close as soon as possible, however they do open first... :)

        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

        J Offline
        J Offline
        John Robert Wilk
        wrote on last edited by
        #3

        Your right the mutex is over kill what I need to know is which method to override in order to close the child winform objects. I'm new to the dot net platform and still learning.

        L 1 Reply Last reply
        0
        • J John Robert Wilk

          Your right the mutex is over kill what I need to know is which method to override in order to close the child winform objects. I'm new to the dot net platform and still learning.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          I still sense some confusion. You can close a modeless form (that is one shown through Show() as opposed to a modal dialog, which gets shown by calling ShowDialog()) by calling its Close() method, no need to override anything. However, if you want to limit the number of open windows, why not just NOT open them, rather than closing them once you decided they are too many? :)

          Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

          J 1 Reply Last reply
          0
          • L Luc Pattyn

            I still sense some confusion. You can close a modeless form (that is one shown through Show() as opposed to a modal dialog, which gets shown by calling ShowDialog()) by calling its Close() method, no need to override anything. However, if you want to limit the number of open windows, why not just NOT open them, rather than closing them once you decided they are too many? :)

            Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

            J Offline
            J Offline
            John Robert Wilk
            wrote on last edited by
            #5

            Thanks for your help I didn't realize you could make a winform modal.

            1 Reply Last reply
            0
            • J John Robert Wilk

              I have a winform application that opens other winform objects I need to limit these new winform objects to one instance. I understand mutexes but don't know what to override in the winform object to limit it to a single instance.

              M Offline
              M Offline
              Manfred Rudolf Bihy
              wrote on last edited by
              #6

              See my answer (Solution 2) to this question How to open only one instance of class not more[^]. It's exactly what you're looking for. 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