Click here to Skip to main content
13,044,705 members (51,799 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hey again guys! I have a problem.. When i open my second form where i can add things to a listbox in form1 the second form is closing like this:

1. Open the second form
2. Add what i want to add
3. Close...

I don't want the form2 to close i want it to stay so i can add more items at same time to the listbox. How can i do this?
Posted 30-Apr-13 7:03am
ryanb31 30-Apr-13 13:20pm
You likely have code that is closing it.
ExpertITM 30-Apr-13 13:28pm
How you add two form in one page?
Maciej Los 30-Apr-13 13:56pm
Any error occurs?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

OK, don't close it then. This is normally done be ether removing of the close box, or by capturing the event of closing the form and cancellation of its handling, usually hiding the form instead. To do so, you need to handle the event System.Windows.Forms.Form.FormClosing:[^].

Or, alternatively, by overriding of the virtual method System.Windows.Forms.Form.OnFormClosing:[^].

In these cases, fist check up System.Windows.Forms.FormClosingEventArgs.CloseReason. If it is System.Windows.Forms.CloseReason.UserClosing, set System.Windows.Forms.FormClosingEventArgs.Cancel to false. Please see:[^],[^],[^],[^].

I think is should be quite clear now.

However, I would not recommend using multiple form (I don't count modal forms, but even the number of modal forms should be very limited). There are more other problems, forget user convenience. It's much better to live with only one, main form, pretty much like Visual Studio does. Instead of forms, you can put content on many panels which you can show and hide, all kind of accordion-style panels, docking panels (advanced design, like in Visual Studio) or, very simple and clear approach, TabControl.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100