简体   繁体   中英

how to load a form into another form as child from an event of a third form?

Hopefully I can make this as clear as possible

I have 3 forms: frmMain , frmLogin and frmDashboard .

When the application opens frmMain opens as mdiParent with frmLogin as the mdiChild. After users enter correct credentials then frmLogin hides and frmDashboard opens as a child of frmMain .

The problem is I can't seem to get frmMain to be the parent of frmDashboard because it is being opened from frmLogin

The code on the frmLogin login button click is as follow:

if (account_exist == true)
{
   MessageBox.Show("Welcome back ");
   frmDashboard f = new frmDashboard();
   f.Show();
   this.Hide();
}

Can anyone help me with the best way to accomplish this?

Can anyone help me with the best way to accomplish this?

The best and only correct way to do that is by separating concerns .

It is not the responsibility of your login form to do anything but login, and the main form should be notified of the completion of the login process. Once that happens, the main form should present whatever UI element(s) relevant to the post login phase.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM