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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. show form once

show form once

Scheduled Pinned Locked Moved C#
tutorialquestion
4 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.
  • H Offline
    H Offline
    hastk
    wrote on last edited by
    #1

    Please tell me how to show a form only once ? Form frm=new MyForm(); frm.show(); this code will open new form each time I am calling it. thank you

    L J 2 Replies Last reply
    0
    • H hastk

      Please tell me how to show a form only once ? Form frm=new MyForm(); frm.show(); this code will open new form each time I am calling it. thank you

      L Offline
      L Offline
      LiquidE_SA
      wrote on last edited by
      #2

      try showDialog() instead of show(). I don't know if this will work, but try it.

      ASBESTOS-Greetings LiquidE

      J 1 Reply Last reply
      0
      • L LiquidE_SA

        try showDialog() instead of show(). I don't know if this will work, but try it.

        ASBESTOS-Greetings LiquidE

        J Offline
        J Offline
        Jon Hulatt
        wrote on last edited by
        #3

        If you don't know if it'll work, then why bother posting? Tat like that devalues the usefulness of the forums.

        using System.Beer;

        1 Reply Last reply
        0
        • H hastk

          Please tell me how to show a form only once ? Form frm=new MyForm(); frm.show(); this code will open new form each time I am calling it. thank you

          J Offline
          J Offline
          Jon Hulatt
          wrote on last edited by
          #4

          If you define a member variable in your class, then you can test whether the member is null or not to decide whether to show the form:-

          class MyClass
          {
          ...

          MyForm m_frm;

          public void OnButton1Click(object sender, EventArgs e)
          {
          if (m_frm == null)
          {
          m_frm = new MyForm();
          m_form.Show();
          }
          }
          }

          The problem with that is that if the user closes the form, they'll not be able to reopen it. To do that you'd need to handle the form's Closing event, and set the m_frm reference to null.

          using System.Beer;

          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