1. frmHome frm = new frmHome();
frm.Show();
this.Close();
I\'m opening HomeForm
from LoginForm
. In LoginForm
In program.cs:
void Main() {
frmLogin fl = new frmLogin();
if (fl.ShowModal() == DialogResult.Ok) {
frmHome fh = new frmHome();
fh.Show();
}
}
try that it might help you
frmHome frm = new frmHome();
this.hide()
frm.ShowDialog();
this.Close();
I'm not quite sure I'm understanding this, perhaps you could do something like this if you want to loop through a specific order of forms: (pseudo code)
Dim formsList as New List(Of form)
formsList.add(Form1)
formsList.add(Form2)
formsList.add(Form3)
' etc etc etc '
For Each f as Form in formsList
f.ShowDialog()
' you could have a condition here which breaks the for loop perhaps '
Next
Me.close ' close the app '
You could add a condition into the For loop which breaks the for loop to end early...
note: sorry for the vb.net code...but it should be easy to understand though
Why don't you just stop calling application.exit in the form_closed event?
I am not sure that you really need it anyway, and if you do then you can remove the x icon from the screen and give them a close button.
Alternatively there is a CloseReason in the event args that will tell you if it is a user closing the form or code or something else.
One way to accomplish this:
you can force the form to hide, instead of close. instead of catching the form_closed event, catch the form_closing event. it would look something like this.
private void LoginFrm_Closing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Hide();
frmHome frm = new frmHome();
frm.Show();
}
this will keep both open, but only one visible. somewhere in frmHome, possibly a public variable to hold the LoginFrm, so you can toggle between the two with Hide(); and Show(); (and any other forms you may wish to add)
Edit: Grammar.