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. CLOSING FORMS

CLOSING FORMS

Scheduled Pinned Locked Moved C#
csharpvisual-studiohelpjavatutorial
9 Posts 7 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.
  • A Offline
    A Offline
    airmigjr
    wrote on last edited by
    #1

    Hi people, I've a doubt: Today I work with Java, but I started teaching C# to beginners. I created two forms, each one has a button on the middle of the form. When I click the button of the first form, the second form appears and the first form disappears. When I click the button from second form, (the one that appeared), the first form appears and the second form disappears. It's just to teach how the methods .Show() and .Hide() works. Now it's working, but I've a problem: When my software is running over Visual Studio, normally if I were, for example, working with just a form, clicking on (X) to close the app, the IDE came back to development mode. But on my app, after I show some punch of clicks to go to a form and to came back to the other, even if I had been on any of the forms (first or second), if I click to close the app, It does not happens.... I have to click Shift+Control+F5 to came back to development mode, and still doesn't happens again, the form appears, and I have to close it (again), so THEN I go to development mode... Weird.... Could someone help-me ? I'm hiding the first form, and opening the other using

    Form form2 = new Form();
    form2.Show();
    this.Hide();

    and inside the Form2:

    Form form1 = new Form();
    form1.Show();
    this.Hide();

    N V D B L 5 Replies Last reply
    0
    • A airmigjr

      Hi people, I've a doubt: Today I work with Java, but I started teaching C# to beginners. I created two forms, each one has a button on the middle of the form. When I click the button of the first form, the second form appears and the first form disappears. When I click the button from second form, (the one that appeared), the first form appears and the second form disappears. It's just to teach how the methods .Show() and .Hide() works. Now it's working, but I've a problem: When my software is running over Visual Studio, normally if I were, for example, working with just a form, clicking on (X) to close the app, the IDE came back to development mode. But on my app, after I show some punch of clicks to go to a form and to came back to the other, even if I had been on any of the forms (first or second), if I click to close the app, It does not happens.... I have to click Shift+Control+F5 to came back to development mode, and still doesn't happens again, the form appears, and I have to close it (again), so THEN I go to development mode... Weird.... Could someone help-me ? I'm hiding the first form, and opening the other using

      Form form2 = new Form();
      form2.Show();
      this.Hide();

      and inside the Form2:

      Form form1 = new Form();
      form1.Show();
      this.Hide();

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Process won't quit till the main form and all foreground threads finishes executing. If you close the Form1, it should get closed properly. Is that happening?

      Best wishes, Navaneeth My blog

      1 Reply Last reply
      0
      • A airmigjr

        Hi people, I've a doubt: Today I work with Java, but I started teaching C# to beginners. I created two forms, each one has a button on the middle of the form. When I click the button of the first form, the second form appears and the first form disappears. When I click the button from second form, (the one that appeared), the first form appears and the second form disappears. It's just to teach how the methods .Show() and .Hide() works. Now it's working, but I've a problem: When my software is running over Visual Studio, normally if I were, for example, working with just a form, clicking on (X) to close the app, the IDE came back to development mode. But on my app, after I show some punch of clicks to go to a form and to came back to the other, even if I had been on any of the forms (first or second), if I click to close the app, It does not happens.... I have to click Shift+Control+F5 to came back to development mode, and still doesn't happens again, the form appears, and I have to close it (again), so THEN I go to development mode... Weird.... Could someone help-me ? I'm hiding the first form, and opening the other using

        Form form2 = new Form();
        form2.Show();
        this.Hide();

        and inside the Form2:

        Form form1 = new Form();
        form1.Show();
        this.Hide();

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

        airmigjr wrote:

        Today I work with Java, but I started teaching C# to beginners.

        I don't mean to sound negative, but I don't think you should teach C# (yet) if you still have these kind of questions. That doesn't mean you're a bad programmer, but I think you still lack the thorough .Net knowledge to teach it. I'm working with .Net for almost 10 year now (since 1.0) and I wouldn't even want to teach it.

        V.
        (MQOTD Rules and previous Solutions )

        J 1 Reply Last reply
        0
        • A airmigjr

          Hi people, I've a doubt: Today I work with Java, but I started teaching C# to beginners. I created two forms, each one has a button on the middle of the form. When I click the button of the first form, the second form appears and the first form disappears. When I click the button from second form, (the one that appeared), the first form appears and the second form disappears. It's just to teach how the methods .Show() and .Hide() works. Now it's working, but I've a problem: When my software is running over Visual Studio, normally if I were, for example, working with just a form, clicking on (X) to close the app, the IDE came back to development mode. But on my app, after I show some punch of clicks to go to a form and to came back to the other, even if I had been on any of the forms (first or second), if I click to close the app, It does not happens.... I have to click Shift+Control+F5 to came back to development mode, and still doesn't happens again, the form appears, and I have to close it (again), so THEN I go to development mode... Weird.... Could someone help-me ? I'm hiding the first form, and opening the other using

          Form form2 = new Form();
          form2.Show();
          this.Hide();

          and inside the Form2:

          Form form1 = new Form();
          form1.Show();
          this.Hide();

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

          You didn't close the startup form. You closed another INSTANCE of Form1. You should not have used Show to show Form2. You should have used ShowDialog. That way, when Form2 closes, the original instance of Form1 gets control back. Though, the down-side to using this is that Form1 code blocks until Form2 closes.

          Form2 form2 = new Form();
          this.Hide();
          form2.ShowDialog();    ' Blocks until form2 closes
          this.Show();
          

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          A 1 Reply Last reply
          0
          • A airmigjr

            Hi people, I've a doubt: Today I work with Java, but I started teaching C# to beginners. I created two forms, each one has a button on the middle of the form. When I click the button of the first form, the second form appears and the first form disappears. When I click the button from second form, (the one that appeared), the first form appears and the second form disappears. It's just to teach how the methods .Show() and .Hide() works. Now it's working, but I've a problem: When my software is running over Visual Studio, normally if I were, for example, working with just a form, clicking on (X) to close the app, the IDE came back to development mode. But on my app, after I show some punch of clicks to go to a form and to came back to the other, even if I had been on any of the forms (first or second), if I click to close the app, It does not happens.... I have to click Shift+Control+F5 to came back to development mode, and still doesn't happens again, the form appears, and I have to close it (again), so THEN I go to development mode... Weird.... Could someone help-me ? I'm hiding the first form, and opening the other using

            Form form2 = new Form();
            form2.Show();
            this.Hide();

            and inside the Form2:

            Form form1 = new Form();
            form1.Show();
            this.Hide();

            B Offline
            B Offline
            BobJanova
            wrote on last edited by
            #5

            This is entirely the wrong way to demonstrate Show/Hide. Multi-form UIs are difficult to get right, and coding up the example that you are using correctly will introduce a whole bunch of concepts (about main forms, the application loop and Program.cs) that are not relevant to the point. Just have a button on your main form that shows or hides the secondary one. And why are you creating a new instance each time? Such an elementary misunderstanding of objects and classes indicates that you shouldn't really be teaching people about any OO environment.

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              You didn't close the startup form. You closed another INSTANCE of Form1. You should not have used Show to show Form2. You should have used ShowDialog. That way, when Form2 closes, the original instance of Form1 gets control back. Though, the down-side to using this is that Form1 code blocks until Form2 closes.

              Form2 form2 = new Form();
              this.Hide();
              form2.ShowDialog();    ' Blocks until form2 closes
              this.Show();
              

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak

              A Offline
              A Offline
              airmigjr
              wrote on last edited by
              #6

              Very thank's Mr. Kreskowiak. You helped-me very very much!!! Thank's Again!, and Best Regards!

              D 1 Reply Last reply
              0
              • V V 0

                airmigjr wrote:

                Today I work with Java, but I started teaching C# to beginners.

                I don't mean to sound negative, but I don't think you should teach C# (yet) if you still have these kind of questions. That doesn't mean you're a bad programmer, but I think you still lack the thorough .Net knowledge to teach it. I'm working with .Net for almost 10 year now (since 1.0) and I wouldn't even want to teach it.

                V.
                (MQOTD Rules and previous Solutions )

                J Offline
                J Offline
                Jegan Thiyagesan
                wrote on last edited by
                #7

                I totally agree with you.

                Think! Don't write a line of code unless you absolutely need to.

                1 Reply Last reply
                0
                • A airmigjr

                  Very thank's Mr. Kreskowiak. You helped-me very very much!!! Thank's Again!, and Best Regards!

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

                  As far as teaching this class, you and your students are still screwed. You don't have the prerequisite knowledge to teach this stuff. You're just going to be guessing at how things work and the only thing worse that not knowing anything at all about what you're learning is being completely misinformed about what you're learning, and that's the path you're leading these students down.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak

                  1 Reply Last reply
                  0
                  • A airmigjr

                    Hi people, I've a doubt: Today I work with Java, but I started teaching C# to beginners. I created two forms, each one has a button on the middle of the form. When I click the button of the first form, the second form appears and the first form disappears. When I click the button from second form, (the one that appeared), the first form appears and the second form disappears. It's just to teach how the methods .Show() and .Hide() works. Now it's working, but I've a problem: When my software is running over Visual Studio, normally if I were, for example, working with just a form, clicking on (X) to close the app, the IDE came back to development mode. But on my app, after I show some punch of clicks to go to a form and to came back to the other, even if I had been on any of the forms (first or second), if I click to close the app, It does not happens.... I have to click Shift+Control+F5 to came back to development mode, and still doesn't happens again, the form appears, and I have to close it (again), so THEN I go to development mode... Weird.... Could someone help-me ? I'm hiding the first form, and opening the other using

                    Form form2 = new Form();
                    form2.Show();
                    this.Hide();

                    and inside the Form2:

                    Form form1 = new Form();
                    form1.Show();
                    this.Hide();

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

                    A windows App process will not close until the Main method exits. And you're creating a new instance of the forms on each button click. What you should ideally be doing is to create a private member of Form2 in Form1 and instantiate it in the Form1's constructor or when it is first used (and vice versa for Form2).

                    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