[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# -- close "Login.cs", keep "Main.cs" open

Posted on 2009-12-23
6
Medium Priority
?
231 Views
Last Modified: 2013-12-17
How can I get the below Login.cs
method to "dispose" without
killing "MainForm.cs" ?

this.Dispose(); and this.Close();
both cause "MainForm.cs" to also close.
------------------------------------------------------------------
        private void btnLogin_Click(object sender, EventArgs e)
        {
            GetUserIDTableAdapter AdapterUID = new GetUserIDTableAdapter();
            DataSet1.GetUserIDDataTable dtUserId = AdapterUID.GetData(vLogin.Text, vPassword.Text);
            if (dtUserId.Rows.Count > 0)
            {
                MainForm frm = new MainForm();
                frm.Show();
                // this.Dispose();
            }
            else
            {
                MessageBox.Show("Login Failed");
            }
        }
0
Comment
Question by:finance_teacher
  • 4
6 Comments
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 26113990
u can't.
what i suggest u to do is to use the following code:
 private void btnLogin_Click(object sender, EventArgs e)
        {
            GetUserIDTableAdapter AdapterUID = new GetUserIDTableAdapter();
            DataSet1.GetUserIDDataTable dtUserId = AdapterUID.GetData(vLogin.Text, vPassword.Text);
            if (dtUserId.Rows.Count > 0)
            {
this.Hide();
                MainForm frm = new MainForm();
                frm.ShowDialog();
this.Close();
            }
            else
            {
                MessageBox.Show("Login Failed");
            }
        }
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 26114000
when u close/dispose the login form it disposes all "internal" instances and one of them is your main form.
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 26114011
besides, it would be more UI to allow the user to go back from main form once logged in, and maybe use the login form again with different user/password.

for instance:
private void btnLogin_Click(object sender, EventArgs e)
        {
            GetUserIDTableAdapter AdapterUID = new GetUserIDTableAdapter();
            DataSet1.GetUserIDDataTable dtUserId = AdapterUID.GetData(vLogin.Text, vPassword.Text);
            if (dtUserId.Rows.Count > 0)
            {
this.Hide();
                MainForm frm = new MainForm();
                if(frm.ShowDialog() == DialogResult.OK){
this.Show();
}
else{
this.Close();
}
            }
            else
            {
                MessageBox.Show("Login Failed");
            }
        }
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 2000 total points
ID: 26114027
just set the this.DialogResult in the main form when leaving the form.
assume that if the user click OK, the login form is displayed again to allow him to login with different user/password, and if cancel then exit applciation.
0
 

Author Comment

by:finance_teacher
ID: 26114034
this.Hide(); works good
0
 
LVL 9

Expert Comment

by:magicdlf
ID: 26114049
Not sure if this will help. Just take a look. Good luck
http://bytes.com/topic/c-sharp/answers/449265-self-restarting-application
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question