4

Is it possible to close all the open forms in a Windows Mobile 6.5 project using VB.NET?
I found some approaches for a desktop solution, something like:

For Each f As Form In My.Application.OpenForms
    f.Close()
Next


...which seems not possible in WM6.5?

Any idea or approach to do this is much appreciated.

seph
  • 674
  • 2
  • 8
  • 23
  • Why not just call Application.Exit? – Hans Passant Dec 18 '13 at 14:25
  • @HansPassant Thanks for your answer. That would indeed be an idea, but I later on want to let the main form (and maybe some others) still opened. That's the reason I would rather want an approach like in the OP. – seph Dec 18 '13 at 14:34
  • 3
    Clearly you asked the wrong question, not sure what the point might be. If you lose track of all your open forms on a mobile app then you are doing it wrong. Just storing them in a List and removing them again with the FormClosed event is a simple approach. – Hans Passant Dec 18 '13 at 14:42
  • @HansPassant I could have formulated my question better, you are right. But no need to accuse me of doing things "wrong" or "right". Even without showing you some code of mine, I know that there is a lot of room for improvement, there always is, right? – seph Dec 18 '13 at 14:49
  • 1
    Yeah, you need to create or use a framework that tracks the open forms for you. In a mobile app the number should be small, and the task should be pretty easy. – ctacke Dec 19 '13 at 04:55

1 Answers1

3

Close all forms except the one where this code is

            For i = System.Windows.Forms.Application.OpenForms.Count - 1 To 1 Step -1
                Dim form As Form = System.Windows.Forms.Application.OpenForms(i)
                form.Close()
            Next i

'Sorry for my poor english

Branquinho
  • 31
  • 5