Switch Between Two Forms

Hello, I am very new to the .NET framework; I only know beginner level code. I am programming in C++ and I basically created two Forms. One Form was created when I started up Visual Studio (Form1), and the other I made using the "Add New Item" menu option (Form1). I basically want to have a button on Form1 that when clicked will show Form2. Then, a button on Form2 what will go back to Form1. How would I go about doing this  I found a way to show Form2 from Form1 by making a new Form2, and then calling either Show() or ShowDialog() on it. However Form1 still shows and Form2 is never shown exactly in the same spot Form1 was. How would I fix this  Thank you very much for any help you are able to offer me.

Answer this question

Switch Between Two Forms

  • jritenburg

    You should explicitly declare where form2 will show up rather than using the defaults.  The defaults should be either window center or "let .net decide".  :)  Also, if you wish to make form1 appear invisible, just call the .Hide once you're done preparing the form2.  You can also pass handles to the other form to ensure that it will have knowledge of the calling form.  There are other ways that are more finese, but since you're new to the framework, you might be better off doing it the noob way to get results then researching for a better method.
  • simsj

    How would I pass handles to the other form to ensure that it will have knowledge of the calling form  Also, what would the other ways be (I don't expect code examples, but maybe a starting place). Thank you very much for your help thus far.
  • Vin Brown

    http://www.developerfusion.com/show/4375/9/

    This one's really good by Ged Mead.  Even though it's in vb, it's nicely written.
    http://www.devcity.net/Articles/94/multipleforms.aspx


  • Switch Between Two Forms