Results 1 to 8 of 8

Thread: [RESOLVED] Close previous form

  1. #1

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Resolved [RESOLVED] Close previous form

    Hey there,

    i have a login form, once the users logs in i want to get rid of this form, dispose of it, and open the main application form.

    how do i go about doing this
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Close previous form

    HI,

    Assuming the main application form will remain open thereafter use a module. In the module put something like

    VB Code:
    1. Dim frmLogin As New fclsLogin  (Or whatever you called it)
    2. Friend frmMain As New fclsMain  (or whatever..)
    3.  
    4. Public Sub Main
    5.    frmLogin.ShowDialog
    6.    Application.Run(frmMain)
    7. End Sub

    Then make Sub main your startup object.

    Either use the Close button in the title bar to close the login form or put a button on it with the code

    Me.Close

    If the login is not successful, use Application.Exit to avoid opening the main form. Put a test for this in the closing event of the login form.
    Last edited by taxes; Aug 31st, 2005 at 07:03 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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

    Re: Close previous form

    I agree with taxes in principle but I think he is over-complicating things a bit:
    VB Code:
    1. Dim frmLogin As New fclsLogin  (Or whatever you called it)
    2. Friend frmMain As New fclsMain  (or whatever..)
    3.  
    4. Public Sub Main
    5.    If frmLogin.ShowDialog() = DialogResult.OK Then
    6.        Application.Run(frmMain)
    7.    End If
    8. End Sub
    This way you just return OK for a successful login and anything else for a failure. There is no need to call Application.Exit or anything like that because any DialogResult other than OK will bypass the main form and the app will exit.
    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

  4. #4

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: Close previous form

    how do i get the login form to return a dialog result
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Close previous form

    Quote Originally Posted by Strider
    how do i get the login form to return a dialog result

    Hi,

    Looks like jmcilhinney has shut down for the day.

    DialogResult is a property of the form. You can set it when you validate the login entry. BUT if you allow the Close button in the titlebar to be used, the form will remain open, but hidden, so you have to dispose it.

    You will find that jmcilhinney's suggestion takes as much code as mine, so take your pick.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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

    Re: Close previous form

    To have ShowDialog return a value you simply set the DialogResult property of the form. Doing so will hide the form and cause ShowDialog to return the value you set. As taxes pointed out, in this situation you need to Dispose the form, which I neglected because I copied and pasted the code. Note that the form does not get Disposed when displayed using ShowDialog whether the Close button is used or you set the DialogResult explicitly. The Close button simply sets the DialogResult to Cancel. Here's what I would do myself:
    VB Code:
    1. Public Sub Main
    2.     Dim login As New LoginForm
    3.  
    4.     If login.ShowDialog() = DialogResult.OK Then
    5.         login.Dispose()
    6.         Application.Start(New MainForm)
    7.     Else
    8.         login.Dispose()
    9.     End If
    10. End Sub
    or
    VB Code:
    1. Public Sub Main
    2.     Dim login As New LoginForm
    3.     Dim loginResult As DialogResult = login.ShowDialog()
    4.  
    5.     login.Dispose()
    6.  
    7.     If loginResult = DialogResult.OK Then
    8.         Application.Start(New MainForm)
    9.     End If
    10. End Sub
    Then you just set the DialogResult property of the login form to OK for a successful login and something else otherwise. Even though it is not strictly necessary to distinguish, I'd set it to Cancel if the user cancels the login and Abort if the login fails some prescribed number of times, which is often three. You would normally assign an OK and a Cancel button to the AcceptButton and CancelButton properties of the login form. This will automatically assign Cancel to the CancelButton's DialogResult property, which in turn assigns it to the form's DialogResult property when clicked. You would then validate the credentials in the Click event handler of the OK button and set the form's DialogResult property to OK only if the login is successful.
    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

  7. #7

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: Close previous form

    excellent, that helps me get my head round it all, cheers guys
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  8. #8
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [RESOLVED] Close previous form

    Application.Start not getting any where

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