943,948 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 38240
  • VB.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 1st, 2006
-2

How to unload all open forms

Expand Post »
Hi All,
I need some guidance here...How does one close or unload all open forms in VB.Net. Can someone please help me out in this regard?
Thanks very much.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hari12341 is offline Offline
6 posts
since Feb 2006
Oct 1st, 2006
0

Re: How to unload all open forms

Application.Exit()
Reputation Points: 53
Solved Threads: 6
Junior Poster in Training
Inanna is offline Offline
90 posts
since Sep 2006
Oct 2nd, 2006
0

Re: How to unload all open forms

i may try that out but this is the warning issued in msdn under application.exit() method

CAUTION The Form.Closed and Form.Closing events are not raised when the Application.Exit method is called to exit your application. If you have validation code in either of these events that must be executed, you should call the Form.Close method for each open form individually before calling the Exit method.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hari12341 is offline Offline
6 posts
since Feb 2006
Oct 2nd, 2006
0

Re: How to unload all open forms

I used a for in vb to close all open forms but i am new to .Net and have not been able to do the same in .Net
Code in VB:

VB.NET Syntax (Toggle Plain Text)
  1. for each frm in forms
VB.NET Syntax (Toggle Plain Text)
  1. frm.close()
VB.NET Syntax (Toggle Plain Text)
  1. next

In .Net this does not work i guess...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hari12341 is offline Offline
6 posts
since Feb 2006
Oct 2nd, 2006
0

Re: How to unload all open forms

hmn:
VB.NET Syntax (Toggle Plain Text)
  1. for each XFrm in forms
  2. unload XFrm
  3. next XFrm
?
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Oct 3rd, 2006
0

Re: How to unload all open forms

Quote ...
CAUTION The Form.Closed and Form.Closing events are not raised when the Application.Exit method is called to exit your application. If you have validation code in either of these events that must be executed, you should call the Form.Close method for each open form individually before calling the Exit method.
If you're using .NET 2.0 then that's not the case anymore. Application.Exit() raises the Form.Closing events.
Reputation Points: 53
Solved Threads: 6
Junior Poster in Training
Inanna is offline Offline
90 posts
since Sep 2006
Oct 4th, 2006
1

Re: How to unload all open forms

This is for VB Express 2005:
VB.NET Syntax (Toggle Plain Text)
  1. For i As Integer = My.Application.OpenForms.Count - 1 To 0 Step -1
  2. If My.Application.OpenForms.Item(i) IsNot Me Then
  3. My.Application.OpenForms.Item(i).Close()
  4. End If
  5. Next i
Reputation Points: 84
Solved Threads: 58
Posting Pro in Training
waynespangler is offline Offline
461 posts
since Dec 2002
Feb 29th, 2008
0

Re: How to unload all open forms

Click to Expand / Collapse  Quote originally posted by Inanna ...
If you're using .NET 2.0 then that's not the case anymore. Application.Exit() raises the Form.Closing events.

Application.Exit() causes all the dialogs to get closed. but, It creates some problems in my test applicatin. is there anyother way to close all the opened forms by the current Application..??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
syeedsan is offline Offline
1 posts
since Feb 2008
Feb 29th, 2008
0

Re: How to unload all open forms

end
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,142 posts
since Nov 2007
Sep 23rd, 2009
0

Re: How to unload all open forms

Well I've try also the code below:
VB.NET Syntax (Toggle Plain Text)
  1. Dim openForm As Form = Nothing
  2.  
  3. For index As Integer = My.Application.OpenForms.Count - 1 To 0 Step -1
  4. openForm = My.Application.OpenForms.Item(index)
  5. If openForm IsNot Me AndAlso Not TypeOf openForm Is DevExpress.Utils.Win.TopFormBase Then
  6. openForm.Close()
  7. openForm.Dispose()
  8. openForm = Nothing
  9. End If
  10. Next

but there were some forms that were not close or rather I say was not detected as openforms.

My question is when during opening the form and it encounters some errors but still able to load the form, does the form considered as not an openform?
Last edited by jireh; Sep 23rd, 2009 at 3:03 am.
Reputation Points: 11
Solved Threads: 49
Posting Whiz
jireh is offline Offline
316 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Passing an event as a parameter
Next Thread in VB.NET Forum Timeline: vb.net increment





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC