【发布时间】:2014-10-08 22:32:35
【问题描述】:
我有一个 MDI 应用程序,我正在尝试获取 ComponentOne 功能区菜单的打开窗口列表。使用 VB .NET。
我有这个子用于在 MDI 容器中实例化一个新的子窗体:
Private Sub newButton_Click(sender As Object, e As EventArgs) Handles newButton.Click
' Create a new instance of the child form.
Dim ChildForm As New MyProject.MyForm
'Make it a child of this MDI form before showing it.
ChildForm.MdiParent = Me
m_ChildFormNumber += 1
ChildForm.Text = "Window " & m_ChildFormNumber
ChildForm.Show()
End Sub
然后在功能区菜单的另一个 Sub 中,我尝试获取窗口列表。 我试过这个:
Dim frm As System.Windows.Window
For Each frm In My.Application.Windows
frmButton = New C1.Win.C1Ribbon.RibbonButton(frm.Title)
...
但是我在System.Windows.Window 集合上得到了一个NullReferenceException。
所以我尝试了这个:
For Each Window In My.Application.Windows
frmButton = New C1.Win.C1Ribbon.RibbonButton(Window.Title)
...
但是,在新的RibbonButton 的参数上,我得到“重载解析失败,因为在没有缩小转换的情况下无法调用可访问的'new'”。如果我打开Option Strict,当然它会说它不允许后期绑定。
所以我想最终我想知道为什么我的 Windows 集合是空的,即使我已经打开了子表单。 那么,除此之外,为什么 New RibbonButton 接受 frm.Title 而不是 Window.Title。
注意(如果您想知道的话)... frmButton 是一个类对象:
Friend WithEvents frmButton As C1.Win.C1Ribbon.RibbonButton
谢谢!
【问题讨论】:
-
Winforms 和 WPF 代码的奇怪组合。使用父级的 MdiChildren 属性。摆脱 WPF 引用,它们会给你带来麻烦。
-
OK - 改用 MdiChildren 有效
-
您指的是哪些 WPF 引用?
-
他指的是
Dim frm As System.Windows.Window的 WinForms 应该是System.Windows.Forms.Form或只是Form因为你不应该添加所有的命名空间
标签: vb.net mdi componentone