Reputation: 139
I have a form called Chatbox that i use for each contact that is clicked.
I do this with following code:
Dim ChatBoxWindow As New Chatbox
labelhandlename = DirectCast(sender, Label).Name
ChatBoxWindow.Name = labelhandlename
Chat_WindowList.Add(ChatBoxWindow)
ChatBoxWindow.Show()
What i want to do is check ---
Sub Chatbox(sender As System.Object, e As System.EventArgs)
labelhandlename = DirectCast(sender, Label).Name
Dim thisOne = Chat_WindowList.FirstOrDefault(Function(x) x.Name = labelhandlename)
If Chatbox.name = labelhandlename Then
thisOne.Focus()
Else
Dim ChatBoxWindow As New Chatbox
ChatBoxWindow.Name = labelhandlename
Chat_WindowList.Add(ChatBoxWindow)
ChatBoxWindow.Show()
End If
End Sub
Whats the best way to do this? (note: chatbox.name doesn't work)
Upvotes: 0
Views: 799
Reputation: 139
Sub Chatbox(sender As System.Object, e As System.EventArgs)
labelhandlename = DirectCast(sender, Label).Name
Dim thisOne = Chat_WindowList.FirstOrDefault(Function(x) x.Name = labelhandlename)
If thisOne IsNot Nothing Then
thisOne.Focus()
Else
Dim ChatBoxWindow As New Chatbox
ChatBoxWindow.Name = labelhandlename
Chat_WindowList.Add(ChatBoxWindow)
ChatBoxWindow.Show()
End If
End Sub
thanks to @VisualVincent AND @Plutonix
Upvotes: 0
Reputation: 2060
You can try:
For Each myForm As Form In Application.OpenForms
If myForm.Name = "something" Then
' Do something.
Else
' Do something else.
End If
Next
Application.OpenForms gets a collection of open forms owned by the application.
But make sure to take a look at this question and answer, as Plutonix suggests.
Upvotes: 1