Opening a new Form when one Form becomes visible

E

Evan Stone

This seems like it *should* be a fairly straigtforward thing to do in
C#/.NET, but I'm finding it a bit befuddling. I'd like to display a dialog
when one form opens, sort of like the following use case:

1. Application starts.
2. Form1 shows.
3. Form2 shows modally, with Form2.ShowDialog(Form1);
4. User closes Form2.
5. Form1 remains visible.

Any suggestions? I tried showing the second form on the Activated event but
that produced weird results, so if anyone has any ideas about this I'd
appreciate it. I'm sure it's a simple thing that I'm overlooking (as usual).

Thanks!

evan stone | software engineer
 
G

Guest

You were on the right track, but you need to add the following:

bool firstTime = true;
private void Form1_Activated(object sender, System.EventArgs e)
{
if (firstTime)
{
firstTime = false;
Form2 frm = new Form2();
frm.ShowDialog(this);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top