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. Prevent Multiple Forms

Prevent Multiple Forms

Scheduled Pinned Locked Moved C#
question
6 Posts 5 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.
  • D Offline
    D Offline
    dimx2
    wrote on last edited by
    #1

    Hello, i have this code and i would like to prevent multipe new forms from opening [quote] private void View_Click(object sender, EventArgs e) { Export export = new Export(); export.Show(); } [/quote] Any Idea of how i can implement this? :confused: D.M -- modified at 11:01 Monday 16th January, 2006

    E T M H 4 Replies Last reply
    0
    • D dimx2

      Hello, i have this code and i would like to prevent multipe new forms from opening [quote] private void View_Click(object sender, EventArgs e) { Export export = new Export(); export.Show(); } [/quote] Any Idea of how i can implement this? :confused: D.M -- modified at 11:01 Monday 16th January, 2006

      E Offline
      E Offline
      exhaulted
      wrote on last edited by
      #2

      Have a bool value and set it to true when the export object is created.

      bool exportCreated = false;

      private void View_Click(object sender, EventArgs e)
      {
      if (!(exportCreated))
      {
      Export export = new Export();
      export.Show();
      exportCreated = true;
      }
      }

      Until you set exportCreated to false a new export object will not be able to be created. Cheers Kev

      1 Reply Last reply
      0
      • D dimx2

        Hello, i have this code and i would like to prevent multipe new forms from opening [quote] private void View_Click(object sender, EventArgs e) { Export export = new Export(); export.Show(); } [/quote] Any Idea of how i can implement this? :confused: D.M -- modified at 11:01 Monday 16th January, 2006

        T Offline
        T Offline
        tarasn
        wrote on last edited by
        #3

        You can show your form as modal dialog private void View_Click(object sender, EventArgs e) { Export export = new Export(); export.ShowDialog(this); } DevIntelligence.com - My blog for .Net Developers

        D 1 Reply Last reply
        0
        • T tarasn

          You can show your form as modal dialog private void View_Click(object sender, EventArgs e) { Export export = new Export(); export.ShowDialog(this); } DevIntelligence.com - My blog for .Net Developers

          D Offline
          D Offline
          dimx2
          wrote on last edited by
          #4

          thanx a lot both of u :) D.M

          1 Reply Last reply
          0
          • D dimx2

            Hello, i have this code and i would like to prevent multipe new forms from opening [quote] private void View_Click(object sender, EventArgs e) { Export export = new Export(); export.Show(); } [/quote] Any Idea of how i can implement this? :confused: D.M -- modified at 11:01 Monday 16th January, 2006

            M Offline
            M Offline
            microsoc
            wrote on last edited by
            #5

            hi! :) you can also try this... :) private Export m_frmExport = null; private void View_Click(object sender, EventArgs e) { if (m_frmExport == null || m_frmExport.IsDisposed) { m_frmExport = new Export(); m_frmExport.Show(); } else { //If the m_frmExport is not yet closed/disposed, this will set the focus on this form. m_frmExport.Activate(); } } hope that helps. :)

            1 Reply Last reply
            0
            • D dimx2

              Hello, i have this code and i would like to prevent multipe new forms from opening [quote] private void View_Click(object sender, EventArgs e) { Export export = new Export(); export.Show(); } [/quote] Any Idea of how i can implement this? :confused: D.M -- modified at 11:01 Monday 16th January, 2006

              H Offline
              H Offline
              Hesham Desouky
              wrote on last edited by
              #6

              is your export form should be modal? If not, you can make your export form as class member and construct it in your main form contstructor and at View_Click(..) you can write only exportForm.Show(); Hope this help Hesham

              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