473,424 Members | 1,856 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,424 software developers and data experts.

How to close Form1 when Form2 displays ??

7 9538
Assuming that Form1 is displaying Form2 then you could have something
similar to the following code.

Form2 f = new Form2();
f.Show();
this.Close();

Be cautioned, however, that if Form1 is the main Form (startup Form) then
closing it will end the application. If this is the case then you may
consider displaying Form2 using its ShowDialog method instead, or you could
hide Form1 instead of closing it.

--
Tim Wilson
..Net Compact Framework MVP

"ematrix" <it******@eyou.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...

Nov 17 '05 #2
Thanks a lot

But that two methods are not good,can I change Form2 to main form before
closing Form1,thanks
Nov 17 '05 #3
AFAIK, no, you cannot. What is the purpose of Form1? Why is it the first one
to be shown but also must close?

--
Tim Wilson
..Net Compact Framework MVP

"ematrix" <it******@eyou.com> wrote in message
news:u7****************@TK2MSFTNGP10.phx.gbl...
Thanks a lot

But that two methods are not good,can I change Form2 to main form before
closing Form1,thanks

Nov 17 '05 #4
Form2 is the main form for working but Form1 is a form used for logging
only.
"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> дÈëÏûÏ¢
news:#o**************@TK2MSFTNGP10.phx.gbl...
AFAIK, no, you cannot. What is the purpose of Form1? Why is it the first one to be shown but also must close?

--
Tim Wilson
.Net Compact Framework MVP

"ematrix" <it******@eyou.com> wrote in message
news:u7****************@TK2MSFTNGP10.phx.gbl...
Thanks a lot

But that two methods are not good,can I change Form2 to main form before closing Form1,thanks


Nov 17 '05 #5
Thanks a lot
The two methods you considered are not good I think.If open Form2 by
ShowDialog(),form1 is back form2 only;If hide form1 before open form2,form1
is only running after closing form2
Nov 17 '05 #6
So Form1 is used to allow the user to log into the application? Is that
right? There are a couple ways to handle this.

(1)
Ensure that Form2 is set to be the startup Form, the one that is passed to
the "Run" method of the Application class, and then display the login Form
from the Load event of Form2 by calling the login Forms ShowDialog method.
You can see an example of this in the TaskVision sample application
(http://windowsforms.net/Applications...=20&tabindex=8)
..

(2)
Use the ApplicationContext class to initially display the login Form, and
then switch over to Form2 when the login Form is closed and the user is
validated. You can see an example of this in relation to a splash screen
here (http://www.codeproject.com/csharp/Ap...extSplash.asp).

There may be others ways to accomplish this but there are two methods
outlined above and one of those should fit your requirements.

--
Tim Wilson
..Net Compact Framework MVP

"ematrix" <it******@eyou.com> wrote in message
news:e1**************@TK2MSFTNGP12.phx.gbl...
Form2 is the main form for working but Form1 is a form used for logging
only.
"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> дÈëÏûÏ¢
news:#o**************@TK2MSFTNGP10.phx.gbl...
AFAIK, no, you cannot. What is the purpose of Form1? Why is it the first

one
to be shown but also must close?

--
Tim Wilson
.Net Compact Framework MVP

"ematrix" <it******@eyou.com> wrote in message
news:u7****************@TK2MSFTNGP10.phx.gbl...
Thanks a lot

But that two methods are not good,can I change Form2 to main form before closing Form1,thanks



Nov 17 '05 #7
I think it's beautiful
Trying >>>>>>>>
"ematrix" <it******@eyou.com> дÈëÏûÏ¢
news:eA**************@TK2MSFTNGP12.phx.gbl...
Thanks a lot
The two methods you considered are not good I think.If open Form2 by
ShowDialog(),form1 is back form2 only;If hide form1 before open form2,form1 is only running after closing form2

Nov 17 '05 #8

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

Similar topics

6
by: Ashish | last post by:
It might be basics for many but I never gave attention on this before. Steps: Add 2 forms (Form1/Form2) in application. Create a object in Form1 for Form2. Form2 f2 = new Form2(); //line...
4
by: Claudia Fong | last post by:
Hi, I have more than one forms in my program, and I would like to for example, in form1, I will call form2 and in form2 it will call form3. But the problem is when I call form2.Show, it does...
3
by: Gary | last post by:
Hi, I have my main form1 and I want to close it and then show form2, in VB6 I used the following code... unload me form2.show in VB.net I got this far
2
by: Bert Szoghy | last post by:
Hello, I am missing something about Visual Basic .NET module variables and window close events. In the following code, after opening Form2 by clicking a button on Form1 and then closing...
3
by: Karan | last post by:
I am calling finalize when form2 loads and deactivates form1 which closes form1. However, same thing is not happening in form2 because finalize is already called. Does anybody has solution to it....
3
by: rdemyan via AccessMonster.com | last post by:
I need help with code to close two forms at the same time, FormA and FormB. I need code that can be used from either form and needs to work with both a 'Close' button on each form as well as if the...
5
by: Sudha Pune | last post by:
Hi all Just i want to close the form1 when i click the button1 on form1 and the same time i want to load the form2 on the same event. And i dont want to hide the form1 instead of close....
4
by: Jason Huang | last post by:
Hi, In my C# windows form project, how do I in a formA open another formB, and close formA when formB is opened? Thanks for help. Jason
1
by: Suma | last post by:
Hi, i have a problem with the controls .i have to validate Form1 Radio button option is checked or Not in the Form2. even after checking the radio button also in FOrm2 it is always taking as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.