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. HOW TO TRAP FORM TO LOAD ONLY ONCE

HOW TO TRAP FORM TO LOAD ONLY ONCE

Scheduled Pinned Locked Moved C#
csharphelptutorial
5 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.
  • C Offline
    C Offline
    crisjala
    wrote on last edited by
    #1

    HI I'M NEW TO C# I'M CREATING MENU AND DONE BUT THE PROBLEM IS WHEN I CLICK THE MENU ITEM 3 TIMES THE FORM WILL SHOW 3 TIMES AND I WANT TRAP THAT IF THE FORM ALREADY LOADED YOU CANT OPEN THE FORM TWICE UNLESS THE USER CLOSE THE FORM.. HOW TO TRAP FORM TO LOAD ONLY ONCE

    S D 2 Replies Last reply
    0
    • C crisjala

      HI I'M NEW TO C# I'M CREATING MENU AND DONE BUT THE PROBLEM IS WHEN I CLICK THE MENU ITEM 3 TIMES THE FORM WILL SHOW 3 TIMES AND I WANT TRAP THAT IF THE FORM ALREADY LOADED YOU CANT OPEN THE FORM TWICE UNLESS THE USER CLOSE THE FORM.. HOW TO TRAP FORM TO LOAD ONLY ONCE

      S Offline
      S Offline
      Saksida Bojan
      wrote on last edited by
      #2

      If you use ShowDialog() instead Show(). If you use ShowModal(), you will prevent code execution till you close your form. OR declare Form with a global or class scope. And you can put boolean value inside form. And use OnLoad event and Close event to set it to true or false. And before showing you should check that boolean. PS: It is rude to shout

      C 1 Reply Last reply
      0
      • S Saksida Bojan

        If you use ShowDialog() instead Show(). If you use ShowModal(), you will prevent code execution till you close your form. OR declare Form with a global or class scope. And you can put boolean value inside form. And use OnLoad event and Close event to set it to true or false. And before showing you should check that boolean. PS: It is rude to shout

        C Offline
        C Offline
        crisjala
        wrote on last edited by
        #3

        can you give me sample sir on how to do it...

        S 1 Reply Last reply
        0
        • C crisjala

          can you give me sample sir on how to do it...

          S Offline
          S Offline
          Saksida Bojan
          wrote on last edited by
          #4

          First way:

          Form form1 = new Form();
          form1.ShowDiealog();

          second way:

          // Not tested, writing from memory;
          public class testForm : Form
          {
          ...
          public bool opend;

          private void testForm_OnLoad(Object sender, EventArgs e)
          {
          opend = true;
          }

          private void testForm_OnClosing(Object sender, EventArgs e)
          {
          opend = false;
          }
          ...
          }

          // class scope wariable - Same as testForm.opend. At least i think it is called class scope.
          testForm form1 = new testForm(1);
          // Inside menu item method click.
          if (!form1.opend)
          form1.Show();
          else
          form1.Focus();

          1 Reply Last reply
          0
          • C crisjala

            HI I'M NEW TO C# I'M CREATING MENU AND DONE BUT THE PROBLEM IS WHEN I CLICK THE MENU ITEM 3 TIMES THE FORM WILL SHOW 3 TIMES AND I WANT TRAP THAT IF THE FORM ALREADY LOADED YOU CANT OPEN THE FORM TWICE UNLESS THE USER CLOSE THE FORM.. HOW TO TRAP FORM TO LOAD ONLY ONCE

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Writing a post in all capital letters is the on-line equivilent of yelling at the top of your lungs. Read the forum rules post at the top of every forum.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008
            But no longer in 2009...

            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