Launching another form from current form

D

Dan

Hi. I'm trying to launch a second form from code in a first, but it doesn't
seem to working.

Originally I tried to write the code as follows (Form2 has a public method
called AttachDataSet):

Application.Run(new Form2());
Form2.AttachDataSet(ds);
Form2.Show();

However, Intellisense couldn't find the AttachDataSet method using that
code. So I changed it to:

Form2 fm2 = new Form2();
Application.Run(fm2);
fm2.AttachDataSet(ds);
fm2.Show();

But when the code runs, nothing seems to happen. Further, if I put a break
point at fm2.Show, I never get there.

Anybody know (a) what's going on in my current code, and (b) how to do what
I want?

Thanks...

Dan
 
M

Miha Markic [MVP C#]

Hi Dan,

Put the line AttachDataSet(ds); into Form2's constructor and change your
code to:

Form2 fm2 = new Form2();
Application.Run(fm2);
// fm2.Show(); don't need this


Call to Application.Run(fm2); won't return until frm2 is closed.
 
D

Dan

Thanks Miha. If I wanted to launch the form and continuing executing (i.e.
launch the form non-modally), how would I do that?

Miha Markic said:
Hi Dan,

Put the line AttachDataSet(ds); into Form2's constructor and change your
code to:

Form2 fm2 = new Form2();
Application.Run(fm2);
// fm2.Show(); don't need this


Call to Application.Run(fm2); won't return until frm2 is closed.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Dan said:
Hi. I'm trying to launch a second form from code in a first, but it doesn't
seem to working.

Originally I tried to write the code as follows (Form2 has a public method
called AttachDataSet):

Application.Run(new Form2());
Form2.AttachDataSet(ds);
Form2.Show();

However, Intellisense couldn't find the AttachDataSet method using that
code. So I changed it to:

Form2 fm2 = new Form2();
Application.Run(fm2);
fm2.AttachDataSet(ds);
fm2.Show();

But when the code runs, nothing seems to happen. Further, if I put a break
point at fm2.Show, I never get there.

Anybody know (a) what's going on in my current code, and (b) how to do what
I want?

Thanks...

Dan
 
P

Philip Rieck

If you are already in a form's code (inside Form1.xxx()), then get rid of
the Application.Run(),


public void OpenForm()
{
Form2 fm2 = new Form2();
fm2.AttachDataSet(ds);
fm2.Show();
}


Application.Run should only show up once in your app - normally in your
"main".


Dan said:
Thanks Miha. If I wanted to launch the form and continuing executing (i.e.
launch the form non-modally), how would I do that?

Miha Markic said:
Hi Dan,

Put the line AttachDataSet(ds); into Form2's constructor and change your
code to:

Form2 fm2 = new Form2();
Application.Run(fm2);
// fm2.Show(); don't need this


Call to Application.Run(fm2); won't return until frm2 is closed.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Dan said:
Hi. I'm trying to launch a second form from code in a first, but it doesn't
seem to working.

Originally I tried to write the code as follows (Form2 has a public method
called AttachDataSet):

Application.Run(new Form2());
Form2.AttachDataSet(ds);
Form2.Show();

However, Intellisense couldn't find the AttachDataSet method using that
code. So I changed it to:

Form2 fm2 = new Form2();
Application.Run(fm2);
fm2.AttachDataSet(ds);
fm2.Show();

But when the code runs, nothing seems to happen. Further, if I put a break
point at fm2.Show, I never get there.

Anybody know (a) what's going on in my current code, and (b) how to do what
I want?

Thanks...

Dan
 
M

Miha Markic [MVP C#]

Hi,

Philip is absolutely right - Application.Run is used for application to know
when it should close you application (when the form you pass is closed).

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Philip Rieck said:
If you are already in a form's code (inside Form1.xxx()), then get rid of
the Application.Run(),


public void OpenForm()
{
Form2 fm2 = new Form2();
fm2.AttachDataSet(ds);
fm2.Show();
}


Application.Run should only show up once in your app - normally in your
"main".


Dan said:
Thanks Miha. If I wanted to launch the form and continuing executing (i.e.
launch the form non-modally), how would I do that?

Miha Markic said:
Hi Dan,

Put the line AttachDataSet(ds); into Form2's constructor and change your
code to:

Form2 fm2 = new Form2();
Application.Run(fm2);
// fm2.Show(); don't need this


Call to Application.Run(fm2); won't return until frm2 is closed.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Hi. I'm trying to launch a second form from code in a first, but it
doesn't
seem to working.

Originally I tried to write the code as follows (Form2 has a public method
called AttachDataSet):

Application.Run(new Form2());
Form2.AttachDataSet(ds);
Form2.Show();

However, Intellisense couldn't find the AttachDataSet method using that
code. So I changed it to:

Form2 fm2 = new Form2();
Application.Run(fm2);
fm2.AttachDataSet(ds);
fm2.Show();

But when the code runs, nothing seems to happen. Further, if I put a
break
point at fm2.Show, I never get there.

Anybody know (a) what's going on in my current code, and (b) how to do
what
I want?

Thanks...

Dan
 
D

Dan

Thanks a lot guys.

Miha Markic said:
Hi,

Philip is absolutely right - Application.Run is used for application to know
when it should close you application (when the form you pass is closed).

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Philip Rieck said:
If you are already in a form's code (inside Form1.xxx()), then get rid of
the Application.Run(),


public void OpenForm()
{
Form2 fm2 = new Form2();
fm2.AttachDataSet(ds);
fm2.Show();
}


Application.Run should only show up once in your app - normally in your
"main".


Dan said:
Thanks Miha. If I wanted to launch the form and continuing executing (i.e.
launch the form non-modally), how would I do that?

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Hi Dan,

Put the line AttachDataSet(ds); into Form2's constructor and change your
code to:

Form2 fm2 = new Form2();
Application.Run(fm2);
// fm2.Show(); don't need this


Call to Application.Run(fm2); won't return until frm2 is closed.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Hi. I'm trying to launch a second form from code in a first, but it
doesn't
seem to working.

Originally I tried to write the code as follows (Form2 has a public
method
called AttachDataSet):

Application.Run(new Form2());
Form2.AttachDataSet(ds);
Form2.Show();

However, Intellisense couldn't find the AttachDataSet method using that
code. So I changed it to:

Form2 fm2 = new Form2();
Application.Run(fm2);
fm2.AttachDataSet(ds);
fm2.Show();

But when the code runs, nothing seems to happen. Further, if I
put
to
 

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