[英]VB.NET how to check if a form with a specific text is opened
我有一个称为Chatbox的表单,可用于单击的每个联系人。
我使用以下代码执行此操作:
Dim ChatBoxWindow As New Chatbox
labelhandlename = DirectCast(sender, Label).Name
ChatBoxWindow.Name = labelhandlename
Chat_WindowList.Add(ChatBoxWindow)
ChatBoxWindow.Show()
我想做的就是检查-
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
最好的方法是什么? (注意:chatbox.name不起作用)
你可以试试:
For Each myForm As Form In Application.OpenForms
If myForm.Name = "something" Then
' Do something.
Else
' Do something else.
End If
Next
Application.OpenForms获取该应用程序拥有的开放表单的集合。
但是,请务必按照Plutonix的建议看一下这个问题和答案 。
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
感谢@VisualVincent AND @Plutonix
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.