Reputation: 192
I have three forms mainForm
, LoginForm
and AdminForm
. on clicking on a menu item on mainForm
it opens LoginForm
(using ShowDialog
) . I want to open AdminForm
on providing login details correctly but don't want to close mainForm
.
used this code on Loginform
to open AdminForm
this.Hide();
AdminForm adminform = new AdminForm();
adminform.ShowDialog();
this.Close();
What it does is, displays adminForm
separately. Main form focuses out, I want adminForm
to appear as dialog on mainForm
as it does when opening LoginForm
from MainForm
.
Upvotes: 0
Views: 94
Reputation: 3609
If you want to show admin form in your current form this should work. You can't show a dialog inside your own form but Show should work fine
this.IsMdiContainer = true;
AdminForm adminform = new AdminForm();
adminform.MdiParent = this;
adminform.Show();
Upvotes: 0
Reputation: 151
When you use ShowDialog you need to pass in the parent form. So you should do loginForm.ShowDialog(this), then you can do adminForm.ShowDialog(Owner).
Upvotes: 0
Reputation: 8551
You'll have to show AdminForm
from MainForm
after LoginForm
closes. You can use LoginForm.DialogResult
to signal to MainForm
whether login was successful.
// in LoginForm, when login is successful:
this.DialogResult = DialogResult.OK;
// in MainForm:
LoginForm lf = new LoginForm();
DialogResult r = lf.ShowDialog(this);
if (r == DialogResult.OK)
{
AdminForm adminform = new AdminForm();
adminform.ShowDialog(this);
}
Upvotes: 2