vb.net - 通过找出一个表单类是否已经打开,只打开一次表单
问题描述
我有一个菜单列表,其中包含一些打开接受参数的表单的菜单项。目前,当它打开表单时,它将创建另一个表单,而不是关注已经打开的表单。
我看过很多 C# 示例,但很难转换它们。
我已经尝试过这段代码,但我认为它不起作用,因为尽管菜单表单是 mdiContainer 表单,但它打开的表单不是子表单。我已将其作为我想要查找的内容,即打开的特定 CLASS 表单。
For Each child In Me.MdiChildren
If TypeOf child Is frmCustomerPurchaseOrders Then
child.WindowState = FormWindowState.Normal
child.Focus()
Exit Sub
End If
Next
Dim myForm As New frmCustomerPurchaseOrders("NotFullyInvoiced")
myForm.Show()
我查看了 My.Application.OpenForms ,它确实获取了表单文本,但是随着表单文本在打开时发生变化,很难通过表单名称进行匹配。有没有办法检查特定类别的表格是否已经打开?
For Each f As Form In My.Application.OpenForms
MessageBox.Show(f.Text)
Next
但是,如果我走错了路,请告诉我!非常感谢
解决方案
你可以用 OpenForms 做同样的事情,就像你的示例代码用 MdiChildren 做的一样;f
只需检查循环中每个 Form, 的类型:
For Each f As Form In My.Application.OpenForms
If TypeOf f Is frmCustomerPurchaseOrders Then
' ... do something in here with "f" ...
End If
Next
推荐阅读
- javascript - 如何添加新行但不在第一个 x 轴中
- python-3.x - 返回一本字典,用 Scrapy 抓取多个页面
- javascript - 多选插件不显示任何选项
- python - 使用 Builder.load_string 在 Kivy 应用程序上显示变量
- python - 如何使用 Bokeh 生成气泡图
- python - 在 python 中窗口化写入,例如写入 NetCDF
- ruby-on-rails - SidekiqUniqueJobs::UnknownLock: 没有实现`lock::all`
- android - Nativescript - 原生安卓蓝牙低功耗
- javascript - 过滤数据的角度复选框
- integration-testing - 为什么关闭 Pax-Exam 测试需要这么长时间?