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. Windows Forms Problem Closing From One To Another

Windows Forms Problem Closing From One To Another

Scheduled Pinned Locked Moved C#
winformsdebugginghelpquestion
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.
  • V Offline
    V Offline
    Veldor
    wrote on last edited by
    #1

    I have a Main Form that calls various subforms with the following code on a button:

        private void btnForm2\_Click(object sender, EventArgs e)
        {
            using (frmForm2 frmform2 = new frmForm2())
            {
                Hide();
                frmform2.ShowDialog();
                Show();
            }
        }
    

    Then I have a single button on the other form(s) that has this code:

        private void btnOK\_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    

    Everything works great the first run through. I click the button on the main form and it goes away and I get the other form. I click ok on that form and go back to the original. Great! But then if I click to go back to the same form or any form off of the main again. Once that form comes up and I click OK again nothing comes back. As that form closes the original seems like it might briefly be displayed (I see maybe a quick outline of it) before going into never-neverland. The application itself never exits and Im still in debug mode then. I'm obviously doing something really stupid here... Any ideas?

    P 1 Reply Last reply
    0
    • V Veldor

      I have a Main Form that calls various subforms with the following code on a button:

          private void btnForm2\_Click(object sender, EventArgs e)
          {
              using (frmForm2 frmform2 = new frmForm2())
              {
                  Hide();
                  frmform2.ShowDialog();
                  Show();
              }
          }
      

      Then I have a single button on the other form(s) that has this code:

          private void btnOK\_Click(object sender, EventArgs e)
          {
              this.Close();
          }
      

      Everything works great the first run through. I click the button on the main form and it goes away and I get the other form. I click ok on that form and go back to the original. Great! But then if I click to go back to the same form or any form off of the main again. Once that form comes up and I click OK again nothing comes back. As that form closes the original seems like it might briefly be displayed (I see maybe a quick outline of it) before going into never-neverland. The application itself never exits and Im still in debug mode then. I'm obviously doing something really stupid here... Any ideas?

      P Offline
      P Offline
      Pradeep C
      wrote on last edited by
      #2

      I cant reproduce your problem. Please check if the MainForm goes behind any other windows that might be open (like Visual Studio).

      --- "Drawing on my superior command of language I said nothing."

      V 1 Reply Last reply
      0
      • P Pradeep C

        I cant reproduce your problem. Please check if the MainForm goes behind any other windows that might be open (like Visual Studio).

        --- "Drawing on my superior command of language I said nothing."

        V Offline
        V Offline
        Veldor
        wrote on last edited by
        #3

        Well I did say it must be something stupid. Ok yes I have 100 things opened and it was beneath them, but I suppose essentially the same question comes around. Why do I get one result the first time through (The Main Screen shows back on top) and the second run through it does something totally different (The Main Screen shows behind other Windows). Or I suppose, more importantly, how do I fix it?

        S 1 Reply Last reply
        0
        • V Veldor

          Well I did say it must be something stupid. Ok yes I have 100 things opened and it was beneath them, but I suppose essentially the same question comes around. Why do I get one result the first time through (The Main Screen shows back on top) and the second run through it does something totally different (The Main Screen shows behind other Windows). Or I suppose, more importantly, how do I fix it?

          S Offline
          S Offline
          sam
          wrote on last edited by
          #4

          use BringToFront property of your main form e.g. Form2 frm = new Form2(); this.Hide(); frm.ShowDialog(); this.Show(); this.BringToFront();

          V 1 Reply Last reply
          0
          • S sam

            use BringToFront property of your main form e.g. Form2 frm = new Form2(); this.Hide(); frm.ShowDialog(); this.Show(); this.BringToFront();

            V Offline
            V Offline
            Veldor
            wrote on last edited by
            #5

            Yeah that solves the problem, though I dropped all the "this." I just don't know why I've never had to do this in the past. Or why it works on the first run through and back but not the second. I guess I'll just chalk it up to some kind of quirkiness in the MS C# 2005 Express Ed. Debugger. I just "upgraded" to it from a full 2003 version yesterday :)

            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