CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009
    Posts
    1

    [C#] Form Closing

    Hey There, I have a little problem with an application I'm developing.

    There is a login screen, once the user has filled in there details and pressed 'Continue »'
    the following code executes:

    MessageBox.Show("Hey There " + txtUser.Text + "!", ":: Login ::", MessageBoxButtons.OK, MessageBoxIcon.None);
    frmMain frm = new frmMain();
    frm.Show();
    this.Dipose(false);

    Which works fine for hiding frmLogin and diplaying frmMain, however when I close frmMain it doesn't exit the application completely, you can't see it, but it's in the task manager.

    Are there any bits of code you could recommend me using?

    Thanks,
    TehTom

  2. #2
    Join Date
    Dec 2005
    Location
    Waterloo ON
    Posts
    545

    Re: [C#] Form Closing

    Quote Originally Posted by TehTom View Post
    Hey There, I have a little problem with an application I'm developing.

    There is a login screen, once the user has filled in there details and pressed 'Continue ยป'
    the following code executes:

    MessageBox.Show("Hey There " + txtUser.Text + "!", ":: Login ::", MessageBoxButtons.OK, MessageBoxIcon.None);
    frmMain frm = new frmMain();
    frm.Show();
    this.Dipose(false);

    Which works fine for hiding frmLogin and diplaying frmMain, however when I close frmMain it doesn't exit the application completely, you can't see it, but it's in the task manager.

    Are there any bits of code you could recommend me using?

    Thanks,
    TehTom
    Put a line in Form_Closing event handler:
    Code:
    Application.Exit();
    The difficulty is that you have no idea how difficult it is.

    .Net 3.5/VS 2008

  3. #3
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: [C#] Form Closing

    I basically would change the design as why your Login is still open in the background ? There are lots of possibilities to do that in a design without any troubles. One for example would be to open the Form Main as the first form then showing the login screen. If you like people shouldn't see the MainForm before looging in ,simple hide it and show it when the login succeeded If the user fals to login, simple close the login Form and the mainform too.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

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

Featured