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 prevent from open the same form

How to prevent from open the same form

Scheduled Pinned Locked Moved C#
questiontutorial
5 Posts 4 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.
  • N Offline
    N Offline
    nuttynibbles
    wrote on last edited by
    #1

    hi, if i have already open form1, how do i check and not open form1 again??

    I T 2 Replies Last reply
    0
    • N nuttynibbles

      hi, if i have already open form1, how do i check and not open form1 again??

      I Offline
      I Offline
      i gr8
      wrote on last edited by
      #2

      i think there is property called isActiveForm, check using this. or else while opening the form assign a golbal variable (say true), and set this to false on closing that form. using this global variable u can validate whether the form is opened or not

      1 Reply Last reply
      0
      • N nuttynibbles

        hi, if i have already open form1, how do i check and not open form1 again??

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

        assume if you are checking the form "form1", code is below.

        public static Form IsFormAlreadyOpen(Type FormType)
        {
        foreach (Form OpenForm in Application.OpenForms)
        {
        if (OpenForm.GetType() == FormType)
        return OpenForm;
        }
        return null;
        }

            private void button1\_Click(object sender, EventArgs e)
            {
                Form frmTest;
                if ((frmTest = IsFormAlreadyOpen(typeof(Form1))) == null)
                {
                    frmTest = new Form1();
                    frmTest.Show();
                }
                else
                {
                    frmTest.WindowState = FormWindowState.Normal;
                    frmTest.BringToFront();
                }
            }
        

        this code opens the form if it's not already open otherwise it'll make active form. thatraja

        N 1 Reply Last reply
        0
        • T thatraja

          assume if you are checking the form "form1", code is below.

          public static Form IsFormAlreadyOpen(Type FormType)
          {
          foreach (Form OpenForm in Application.OpenForms)
          {
          if (OpenForm.GetType() == FormType)
          return OpenForm;
          }
          return null;
          }

              private void button1\_Click(object sender, EventArgs e)
              {
                  Form frmTest;
                  if ((frmTest = IsFormAlreadyOpen(typeof(Form1))) == null)
                  {
                      frmTest = new Form1();
                      frmTest.Show();
                  }
                  else
                  {
                      frmTest.WindowState = FormWindowState.Normal;
                      frmTest.BringToFront();
                  }
              }
          

          this code opens the form if it's not already open otherwise it'll make active form. thatraja

          N Offline
          N Offline
          nuttynibbles
          wrote on last edited by
          #4

          hi thatraja, tks. erm i forgot to mention that i was doing it for windows mobile =). so Application.OpenForms is not available

          OriginalGriffO 1 Reply Last reply
          0
          • N nuttynibbles

            hi thatraja, tks. erm i forgot to mention that i was doing it for windows mobile =). so Application.OpenForms is not available

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #5

            If this is the same App we talked about yesterday, the list you created to show which forms need to be closed would also double up as a list of open forms wouldn't it? If it needs to be closed at log off, it's open...

            If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            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