Close all forms but one
-
Is there a way in VB.NET 2005 to close all forms (or hide) except the one that is being loaded, without typing a load of code to hide each form? Cheers
I don't remember off the top of my head, but I think you can loop through all of the Form objects and hide all but the one you want to keep open. Hope this starts you off on the right foot...
-
Is there a way in VB.NET 2005 to close all forms (or hide) except the one that is being loaded, without typing a load of code to hide each form? Cheers
The Application object has a property that lists all open forms, you can iterate over that.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
The Application object has a property that lists all open forms, you can iterate over that.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
What do you mean, application.exit.... something??? Im not a wiz at vb by the way, just a beginner!
-
What do you mean, application.exit.... something??? Im not a wiz at vb by the way, just a beginner!
harveyhanson wrote:
Im not a wiz at vb by the way, just a beginner!
This makes me question what you're really trying to do with this. The Application object has a collection called
OpenForms
. All you need to do is iterate over this collection and callHide
on each form, taking care not to hide the form you want to show.For Each f As Form in Application.OpenForms ' Make sure we're not hiding the form this code is on... If f Is Not Me Then f.Hide Next Next
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
harveyhanson wrote:
Im not a wiz at vb by the way, just a beginner!
This makes me question what you're really trying to do with this. The Application object has a collection called
OpenForms
. All you need to do is iterate over this collection and callHide
on each form, taking care not to hide the form you want to show.For Each f As Form in Application.OpenForms ' Make sure we're not hiding the form this code is on... If f Is Not Me Then f.Hide Next Next
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007The aim is to make a goodbye screen, but at the mo it is just over the top of the current form, whereas i want that to be the only form shown! I will have a go with this statement
-
harveyhanson wrote:
Im not a wiz at vb by the way, just a beginner!
This makes me question what you're really trying to do with this. The Application object has a collection called
OpenForms
. All you need to do is iterate over this collection and callHide
on each form, taking care not to hide the form you want to show.For Each f As Form in Application.OpenForms ' Make sure we're not hiding the form this code is on... If f Is Not Me Then f.Hide Next Next
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Dave Kreskowiak wrote:
For Each f As Form in Application.OpenForms ' Make sure we're not hiding the form this code is on... If f Is Not Me Then f.Hide Next Next
That was what I was thinking of yesterday when I replied in the earlier post...
-
The aim is to make a goodbye screen, but at the mo it is just over the top of the current form, whereas i want that to be the only form shown! I will have a go with this statement
Then that's what you do. After that, you can wait a little bit, then call Application.Exit.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
harveyhanson wrote:
Im not a wiz at vb by the way, just a beginner!
This makes me question what you're really trying to do with this. The Application object has a collection called
OpenForms
. All you need to do is iterate over this collection and callHide
on each form, taking care not to hide the form you want to show.For Each f As Form in Application.OpenForms ' Make sure we're not hiding the form this code is on... If f Is Not Me Then f.Hide Next Next
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007is this the exact code i should use? I have tried it and i get how it works, but i am getting an error on "not me" bit, and why is there 2 nexts, wouldnt one just create the loop?!
-
is this the exact code i should use? I have tried it and i get how it works, but i am getting an error on "not me" bit, and why is there 2 nexts, wouldnt one just create the loop?!
That first Next should be an "End If" actually. You should NEVER just copy and paste code. Try and understand any examples and write your own. There's too many "Copy'n'Paste" programmers out there clogging up the forums.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
That first Next should be an "End If" actually. You should NEVER just copy and paste code. Try and understand any examples and write your own. There's too many "Copy'n'Paste" programmers out there clogging up the forums.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Dont worry, i am just trying out code really, not copying and pasting and leaving it that way. Still, what is the "not me" bit about?
-
Dont worry, i am just trying out code really, not copying and pasting and leaving it that way. Still, what is the "not me" bit about?
Me
always referes to the current instance of an object. Since every open form ends up in theOpenForms
collection, that loop has to check to see if it's going to hide the form the code is running on.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007