Click here to Skip to main content
15,896,730 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys,
I seem to lack words to describe what I'm after so I'll show you the code that I wish Were usable.

VB
dim idToView as integer = 3'RANDOM'
dim AlreadyExists as boolean = False



For each X as CertainKindOfWindow in AllOfTheOpenWindowsInThisProgram '<-----Thats What I'm after




    if X.DataRowID = = idToView Then
       
      AlreadyExists = True
      X.BringToFront
      
    end if

Next

if not AlreadyExists then
   OpenNewInstanceOfCertainKindOfWindow(idToView)
end if




I need some Method of examining all of the open windows of a certain class to see weather or not I should open a new instance. I will make the decision Based on the property idToView in each window.
If one of the windows has a matching id then i'll just show that window instead of cluttering my users environment and hogging ram.


Any help on cycling through all open windows is much appreciated. Thanks.
Posted

Application.OpenForms[^] Gets a list of all the open forms in the application. You can then use the above code you posted.
 
Share this answer
 
Comments
Manas Bhardwaj 11-Aug-13 18:59pm    
Seems like you got a better understanding of the question than I had.

+5!
Mr.TMG 11-Aug-13 19:19pm    
That works very well, with one exception. Because i am testing a variable that only exists in a certain type is form; i must first cycle through each form to make sure that it's the type i need to work with and thus contains the property that i need to examine. I will post the code that i have used.

Thank you for your help.
Solved with the help of Ron Beyer and his suggestion of using Application.OpenForms.

Because i am testing a variable that only exists in a certain type of form; i must first cycle through each form to make sure that it's the type i need to work with and thus contains the property that i need to examine.
so make a list of that type of form and use the IS operator to find forms in Application.OpenForms that match.


VB
Sub RespondToClientViewRequest(sender As EPI_Class_Library.EPI_Client, e As EPI_Class_Library.EPI_Class_Events.ClientViewRequestedEventArgs)
     Dim Exists As Boolean = False
     Dim ClientViewForms As New List(Of EPI_Viewers.Veiw_Client_Window)

     For Each x As Form In Application.OpenForms
         If x.GetType Is GetType(EPI_Viewers.Veiw_Client_Window) Then
             ClientViewForms.Add(x)
         End If
     Next

     For Each y As EPI_Viewers.Veiw_Client_Window In ClientViewForms
         If y.ClientDisplay.Client.ID = sender.ID Then
             Exists = True
             y.BringToFront()
         End If
     Next

     If Not Exists Then
         Dim newClient As New EPI_Viewers.Veiw_Client_Window
         newClient.Show()

     End If


 End Sub
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900