I have an MDI form and 2 child forms What i want is, when i click on menu button in MDI, it should open the Login form, when the login is through, from the login form, on button click, I want to close the login form and open the second child form Here is the code i am trying, but it does not open inside the MDI, it opens outside. Please help
this.Close();
frmAdmin frm = new frmAdmin();
frm.MdiParent = this.ParentForm;
frm.Dock = DockStyle.Fill;
frm.Show();
Rewrite the code as follows
frmAdmin frm = new frmAdmin();
frm.MdiParent = this.ParentForm;
this.close();
frm.Dock = DockStyle.Fill;
frm.Show();
Do not call second form from Login
form. Open Login
form as modal dialog, and return login result to the parent form, which will "make decision" based on the login result and open second form.
// Login function in main form
using (var login = new LoginForm())
{
if (login.ShowDialog() == DialogResult.Ok)
{
var admin = new AdminForm
{
MdiParent = this;
Dock = DockStyle.Fill;
}
admin.Show();
}
else
{
// do something when login fails
}
}
With approach above your Login
form will remain with only responsibility to login users.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.