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. if else for forms displayed [modified]

if else for forms displayed [modified]

Scheduled Pinned Locked Moved C#
helptutorial
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.
  • I Offline
    I Offline
    IMC2006
    wrote on last edited by
    #1

    I am creating a new window app and am having difficulty with resetting focus to a form instead of opening multiple instances of the form. I have a menu to open formA for example from the MainForm menu. I want to have the logic be something like (from click of menu from MainForm) If formA visiblity == true then { set focus to formA} else { formA.show} I can't seem to get the syntax for the if condition and the set focus command back to formA if it is already open. Any help would be appreciated, thanks! :confused: -- modified at 1:07 Saturday 27th May, 2006

    S C L 3 Replies Last reply
    0
    • I IMC2006

      I am creating a new window app and am having difficulty with resetting focus to a form instead of opening multiple instances of the form. I have a menu to open formA for example from the MainForm menu. I want to have the logic be something like (from click of menu from MainForm) If formA visiblity == true then { set focus to formA} else { formA.show} I can't seem to get the syntax for the if condition and the set focus command back to formA if it is already open. Any help would be appreciated, thanks! :confused: -- modified at 1:07 Saturday 27th May, 2006

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      if (formA.Visible == true)
      {
      formA.Select();
      }
      else
      {
      formA.Show();
      }


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      I 1 Reply Last reply
      0
      • I IMC2006

        I am creating a new window app and am having difficulty with resetting focus to a form instead of opening multiple instances of the form. I have a menu to open formA for example from the MainForm menu. I want to have the logic be something like (from click of menu from MainForm) If formA visiblity == true then { set focus to formA} else { formA.show} I can't seem to get the syntax for the if condition and the set focus command back to formA if it is already open. Any help would be appreciated, thanks! :confused: -- modified at 1:07 Saturday 27th May, 2006

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        IMC2006 wrote:

        I can't seem to get the syntax for the if condition

        It looks like you partially wrote it in VB The syntax for the if statement is:

        if (/*insert boolean condition here*/)
        {
        // Commands when condition is true
        }
        else
        {
        // Command when condition is false
        }


        "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

        1 Reply Last reply
        0
        • S Stefan Troschuetz

          if (formA.Visible == true)
          {
          formA.Select();
          }
          else
          {
          formA.Show();
          }


          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

          www.troschuetz.de

          I Offline
          I Offline
          IMC2006
          wrote on last edited by
          #4

          I tried this but still it does not function correctly. If formA is not visible then it open a new instance no problem. the problem is if I go back and try and open it again, instead of selecting the previously opened form, it opens a new instance via formA.Show() even though copy of formA is open. If I change visible == true, then it believes an instance is already opened even though one is not opened. if (formA.Visible == false) { // shows new formA form formA.Show(); MessageBox.Show("New Form"); } else { // Reset focus to currently opened form formA.Select(); MessageBox.Show("Reset Focus to form"); }

          1 Reply Last reply
          0
          • I IMC2006

            I am creating a new window app and am having difficulty with resetting focus to a form instead of opening multiple instances of the form. I have a menu to open formA for example from the MainForm menu. I want to have the logic be something like (from click of menu from MainForm) If formA visiblity == true then { set focus to formA} else { formA.show} I can't seem to get the syntax for the if condition and the set focus command back to formA if it is already open. Any help would be appreciated, thanks! :confused: -- modified at 1:07 Saturday 27th May, 2006

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            if(formA == null)
            {
            formA = new FormA();
            }

            if(!formA.Visible)
            {
            formA.Show();
            }

            formA.Focus();

            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