473,320 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to display a form?

Sorry to ask about something so simple. I have researched this for the past
hour and just can't find what I am looking for.

I have a simple C# aplication that has two forms. They are called Form1 and
Form2.

The app starts in Form1. What code do I need to close Form1 and display
Form2?
Nov 16 '05 #1
8 1210
..
..
..
Form2 f = new Form2;
f.Show();
this.Close();
..
..
..
if your Form1 is the one with the main() or you have a menu level form?
ask if need more.

MajorTom

"Keith Smith" <ke*********@verizon.net> wrote in message
news:#c**************@TK2MSFTNGP15.phx.gbl...
Sorry to ask about something so simple. I have researched this for the past hour and just can't find what I am looking for.

I have a simple C# aplication that has two forms. They are called Form1 and Form2.

The app starts in Form1. What code do I need to close Form1 and display
Form2?

Nov 16 '05 #2
That almost worked.

It loaded Form2 breifly (just long enough to display a MessageBox) and then
the whole applcation exited.

If I leave out the "this.Close();" then Form2 stays displayed, except so
does Form1. How can I make it so that Form2 stays open and Form1 closes?

Thank you!


"MajorTom" <m.********@NOverizon.net.do> wrote in message
news:ud**************@TK2MSFTNGP10.phx.gbl...
.
.
.
Form2 f = new Form2;
f.Show();
this.Close();
.
.
.
if your Form1 is the one with the main() or you have a menu level form?
ask if need more.

MajorTom

"Keith Smith" <ke*********@verizon.net> wrote in message
news:#c**************@TK2MSFTNGP15.phx.gbl...
Sorry to ask about something so simple. I have researched this for the

past
hour and just can't find what I am looking for.

I have a simple C# aplication that has two forms. They are called Form1

and
Form2.

The app starts in Form1. What code do I need to close Form1 and display
Form2?


Nov 16 '05 #3
"Keith Smith" <ke*********@verizon.net> wrote:
How can I make it so that Form2 stays open and
Form1 closes?


When your main form closes, the program ends. Try using Hide instead
of Close.

P.
Nov 16 '05 #4
> When your main form closes, the program ends. Try using Hide instead of
Close.

P.


That works to a point... But when I close Form2 the application still
appears to stay running in the background (I concluded that because I have
to hit the "stop" button in order to make it completely exit).

Any ideas how to make the application completely end when I click on the "X"
to close Form2?
Nov 16 '05 #5
Your application started with this line:
Application.Run(new Form1());

this call waits until the form1 ends. Than the execution will continue from
the next line which will exit the function and ultimately exiting the entire
application because its inside the "Main" function. Now when you show the
Form2 and then you close it, you need to call the close method of form1
also. Do something like this:

//inside your Form1 at the time of showing the form2
this.Hide();
Form2 form2 = new Form2();
form2.ShowDialog( this );
//form1 execution is stuck here and waiting for form2 to close so it can
continue doing its thing.
Close(); //the application exits cuz form1 is closing. This line will be
called when the Form2 closes.

Hope that helps.

Ab.
http://joehacker.blogspot.com.

"Keith Smith" <ke*********@verizon.net> wrote in message
news:L5fLd.194$Kj4.85@trnddc09...
When your main form closes, the program ends. Try using Hide instead of
Close.

P.
That works to a point... But when I close Form2 the application still
appears to stay running in the background (I concluded that because I have
to hit the "stop" button in order to make it completely exit).

Any ideas how to make the application completely end when I click on the

"X" to close Form2?

Nov 16 '05 #6
//inside your Form1 at the time of showing the form2
this.Hide();
Form2 form2 = new Form2();
form2.ShowDialog( this );
//form1 execution is stuck here and waiting for form2 to close so it can
continue doing its thing.
Close(); //the application exits cuz form1 is closing. This line will
be
called when the Form2 closes.


Oh I get it now! Thank you so much!
Nov 16 '05 #7
Keith Smith wrote:
Sorry to ask about something so simple. I have researched this for the past
hour and just can't find what I am looking for.

I have a simple C# aplication that has two forms. They are called Form1 and
Form2.

The app starts in Form1. What code do I need to close Form1 and display
Form2?


I believe all you need is this.

//to close form1
form1.Close();

//open form2
form2.Show();
I think you also need to open form2 before you close form1.
-John

Nov 16 '05 #8
RCS
Well, sort of.

You'd need to create an instance of it first:

form2 frmOptions = new form2();
frmOptions.Show();

"John" <jp*****@bellsouth.net> wrote in message
news:1H******************@bignews3.bellsouth.net.. .
Keith Smith wrote:
Sorry to ask about something so simple. I have researched this for the
past hour and just can't find what I am looking for.

I have a simple C# aplication that has two forms. They are called Form1
and Form2.

The app starts in Form1. What code do I need to close Form1 and display
Form2?


I believe all you need is this.

//to close form1
form1.Close();

//open form2
form2.Show();
I think you also need to open form2 before you close form1.
-John

Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
1
by: John Phelan-Cummings | last post by:
When I add the name of a new individual in a, bound form, it will not display that person’s name in a label control of a second unbound form. I have a scheduling program that I am working on. ...
3
by: ApexData | last post by:
I am using a continuous form for display purposes. Above this form, a single record is displayed so that when the user presses my NewButton they can enter a NewRecord which gets added to the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.