Results 1 to 3 of 3

Thread: closing forms

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    closing forms

    Hello

    I have a project that uses a login form and when the user clicks enter it opens another form called customers.
    I have this code in the login form.
    static void Main()
    {
    Application.Run(new frmlogin());
    }

    The problem is when l click enter on the login form to show the customers form. I want to close the login form using this.Close(); but when l do this it exits the entire project.
    I have used this.Visible = false; But then l can't exit the entire project as the form is invisible.

    I think want l really want to do is allow the user to login then close this form, as it is not needed anymore. When the user has finished with the application, they can click on the exit button on the customers form to exit the entire project.

    Any easy way to do this.

    Thanks in advance.

    Steve
    steve

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    Load the login modally from the customer form and use the customer form as the entry point

  3. #3
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    code

    frmMain
    VB Code:
    1. static void Main()
    2.       {
    3.          Application.Run(new frmMain());
    4.       }
    5.  
    6.       private void frmMain_Load(object sender, System.EventArgs e)
    7.       {
    8.          frmLogin f=new frmLogin();
    9.          this.AddOwnedForm(f);
    10.          f.ShowDialog();
    11.       }
    frmLogin
    VB Code:
    1. frmMain f;
    2.       private void frmLogin_Load(object sender, System.EventArgs e)
    3.       {
    4.          f=(frmMain)this.Owner;
    5.       }
    6.  
    7.       private void btnCancel_Click(object sender, System.EventArgs e)
    8.       {
    9.          f.Close();
    10.          this.Close();
    11.       }
    12.  
    13.       private void btnOk_Click(object sender, System.EventArgs e)
    14.       {
    15.          if(txtUsername.Text=="username"&&txtPassword.Text=="password")
    16.             this.Close();
    17.          else MessageBox.Show("Login failed.");
    18.       }
    inspired by dynamic_sysop.

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