Results 1 to 5 of 5

Thread: a very simple question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    25

    a very simple question

    Hi

    While im teaching myself C# ive come across a small problem that is:

    How do i close one form and open the 2nd form in my test app?

    I know thats a n00b question but i've not worked it out for myself?

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    25

    Re: a very simple question

    *Bump*

    Any help please guys cannot seem to get this basic question answered at all

    EDIT:

    I worked out how to open form2 just need to work out how to close form one when form2 is open
    Last edited by Ixl2; Nov 26th, 2005 at 01:59 PM.

  3. #3
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: a very simple question

    if you have the application set to run Form1 on startup, when you close this form the whole application will close. you need to set the application to run from the Main() function. in that function you can do:
    Code:
    Form frm1 = new Form1();
    Form frm2 = new Form2();
    Application.Run(frm1);
    Application.Run(frm2);
    there might be easier ways than that... you could just hide the form incase you want it to reappear later.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: a very simple question

    If you're using C#2005 you can seta project property so that the app does not exit until all forms are closed instead of when the startup form closes. If you're using C# 2003 you can provide this behaviour yourself but it is a pain in the butt. I've provided a submission in the CodeBank that allows you to switch main forms as long as the new main form is created at the time. The code is VB.NET but there's a link to a code converter in my sig.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    25

    Re: a very simple question

    Thanks for the repliys

    What ive done a tmp thing is set form to hide while form 2 is running, but ill look into both your ways and see which is easy.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width