473,660 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unload a form (close a form)



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 show the form2, but
how can I unload form1? If I put form1.close, it will close everything.
:(
In VB, I only have to put
call form2.show
call unload(form1)

I'm new in C#, so could someone help me?

Cheers!
Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
4 21529
On Tue, 17 May 2005 01:50:15 -0700, Claudia Fong wrote:
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 show the form2, but
how can I unload form1? If I put form1.close, it will close everything.
:(

In VB, I only have to put

call form2.show
call unload(form1)

I'm new in C#, so could someone help me?


This is because by default when you create a new WinForm application in C#,
the main method consists of one line of code. That line of code is
Application.Run (new Form1());. The effect of that is that the Application
adds an event handler for the Closed event of the form. In that event
handler it calls ExitThread. So when you close Form1 the application
exits. You would need to remove that line of code and take over
responsibility for when to call Application.Run and when to show Form1, and
when to call Application.Exi tThread.
--
Tom Porterfield
Nov 17 '05 #2
iLo

This is because by default when you create a new WinForm application in C#, the main method consists of one line of code. That line of code is
Application.Run (new Form1());. The effect of that is that the Application
adds an event handler for the Closed event of the form. In that event
handler it calls ExitThread. So when you close Form1 the application
exits. You would need to remove that line of code and take over
responsibility for when to call Application.Run and when to show Form1, and when to call Application.Exi tThread.
Tom Porterfield


Hi, I have the same problem with Claudia
and I have a simple question..
"You would need to remove that line of code" ...where is this line...?? :)
Thanks..
Nov 17 '05 #3
iLo wrote:
Hi, I have the same problem with Claudia
and I have a simple question..
"You would need to remove that line of code" ...where is this line...?? :)
Thanks..


Re-read my response, I stated exactly where it was. And re-read also as I
stated more was needed than simply removing a line of code.
--
Tom Porterfield
Nov 17 '05 #4
I understand the concept of "taking over" the control of the starting/ending
of the application.

However, the practicality is not necessarily the same as the concept.

Could you direct me to a website or other resource that could provide a good
example of how this is accomplished?

Thanks,
~Dan

"Tom Porterfield" wrote:
On Tue, 17 May 2005 01:50:15 -0700, Claudia Fong wrote:
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 show the form2, but
how can I unload form1? If I put form1.close, it will close everything.
:(

In VB, I only have to put

call form2.show
call unload(form1)

I'm new in C#, so could someone help me?


This is because by default when you create a new WinForm application in C#,
the main method consists of one line of code. That line of code is
Application.Run (new Form1());. The effect of that is that the Application
adds an event handler for the Closed event of the form. In that event
handler it calls ExitThread. So when you close Form1 the application
exits. You would need to remove that line of code and take over
responsibility for when to call Application.Run and when to show Form1, and
when to call Application.Exi tThread.
--
Tom Porterfield

Nov 17 '05 #5

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

Similar topics

5
20843
by: Harry J. Smith | last post by:
I have written a Visual Basic program that does a long calculation and writes the results to disk as it runs. If I click the Close button the window closes but the program keeps running. How can I get the program to recognize that its window has been closed and quit running? -Harry http://home.netcom.com/~hjsmith
1
4202
by: salo | last post by:
hi at visual basic 6 i write this to the button1_cl1ck unload form1 form2.show
4
1935
by: V.Boomessh | last post by:
Hai can any one help me on this problem. I am new to VB.NET. I have 2 forms. (form1 and form2) On click of a button in form1 i want to show form2 and unload form1
2
6867
by: brianbender | last post by:
I am trying to load and unload assemblies dynamically and call methods and properties when loaded into an Appdomain I can load assemblies all day in the current AppDomain without references and without interfaces if need be. But try as I may they will ot unload. I have been working on this problem for weeks. I have seen other apps using Remoting but I know there has got to be a way to create a child AppDomain and reference obkect via...
8
17931
by: Sender | last post by:
In VB6.0 we use Unload Form1 to unload (close) form1 - what shall we have to write to unload a form in VB.Net
2
22615
by: sam | last post by:
I want to know how to unload form / application in VB.Net. In VB 6, the coding is Unload Me but how about VB.Net? VB.Net 1.1 Coding -------------------- Private Sub InitializeComponent() Me.SuspendLayout 'MainForm
3
2374
by: lesperancer | last post by:
I've got application A, with a hidden form, whose unload event is cancelled unless you use an 'exit' button (so I can do special processing) this works fine when using just application A and it prevents me from 'x'ing out of msaccess.exe now, I open application A from within application B using the code below
11
2433
by: Stevo | last post by:
I've been using the unload event for a long time. I have this code, which I've abstracted and made into a stripped down simple test case below, and it works fine on the major browsers (IE5+, Firefox, Opera). It also works for all Safari versions before 3.1. It's as if they've deliberately made a change to prevent some actions in the unload handler. Has anyone heard of such a restriction? Here's the test case:
7
2525
by: Shawn | last post by:
Have had a complete brain-fart and cannot think of how to stop code execution without unloading the form in vb.net. In other words, if my code catches an error, I want it to tell the user and stop execution so the user can fix the error and restart the code without unloading the app. Shawn
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1740
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.