By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,987 Members | 1,291 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,987 IT Pros & Developers. It's quick & easy.

Using multiple windows forms

P: n/a
Hi,

I am trying to create an application with multiple windows forms. The
problem that I have is that after creating the window forms, I do not
know how to open formN after closing Main form. Each form is in its
own class. What I want to do is the following:

1. Click a button on Main menu.
2. Close main menu ( I would use hide if possible)
3. Open form2
4. Open other forms and hide or close the previous form.
5. Eventually able to go back to Main form.

I have been experimenting with creating new forms from Main form and
closing/disposing them. However, I would like to learn how to use
forms that I can create using the windows forms that I have created.
Any help is appreciated. Thanks.
Mario

May 19 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Mario wrote:
Hi,

I am trying to create an application with multiple windows forms. The
problem that I have is that after creating the window forms, I do not
know how to open formN after closing Main form. Each form is in its
own class. What I want to do is the following:

1. Click a button on Main menu.
2. Close main menu ( I would use hide if possible)
3. Open form2
4. Open other forms and hide or close the previous form.
5. Eventually able to go back to Main form.

I have been experimenting with creating new forms from Main form and
closing/disposing them. However, I would like to learn how to use
forms that I can create using the windows forms that I have created.
Any help is appreciated. Thanks.
Mario

You need to subscribe to the FormClosing or FormClosed event of your
child on your main form or set a delegate on your child forms which gets
invoked in the closing method of your child forms.
main form:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void cmdChild_Click(object sender, EventArgs e)
{
frmChild Child = new frmChild();
Child.FormClosed += new FormClosedEventHandler(Child_FormClosed);
Child.Show();
this.Hide();
}

void Child_FormClosed(object sender, FormClosedEventArgs e)
{
this.Show();
}

private void cmdChildDelegate_Click(object sender, EventArgs e)
{
frmChildDelegate Del = new frmChildDelegate(new
MethodInvoker(delegate { this.Show(); }));
Del.Show();
this.Hide();
}
}

Delegate child Form:
public partial class frmChildDelegate : Form
{

MethodInvoker ShowParent;

public frmChildDelegate(MethodInvoker showParent)
{
ShowParent = showParent;
InitializeComponent();
}

private void frmChildDelegate_FormClosing(object sender,
FormClosingEventArgs e)
{
ShowParent();
}
}
May 19 '06 #2

P: n/a
Hi John,

Thanks for the reply. I will try your advice and keep you posted.
Thanks.

Mario

May 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.