我有一个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)
...
但我在NullReferenceException
集合上获得了System.Windows.Window
。
所以我试过这个:
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
谢谢!
答案 0 :(得分:0)
感谢来自多个来源的线索,我能够让它运转起来。万一其他人想知道如何,这是我的示例代码:
Public Class mainForm
Private m_ChildFormNumber As Integer
Friend WithEvents frmButton As C1.Win.C1Ribbon.RibbonButton
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 ProofOfConcept.FormResize
'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
Private Sub windowMenu_Dropdown(sender As Object, e As EventArgs) Handles windowMenu.DropDown
Dim count As Integer = Me.MdiChildren.Length
windowMenu.Items.ClearAndDisposeItems()
For i As Integer = 0 To count - 1
frmButton = New C1.Win.C1Ribbon.RibbonButton
frmButton.Text = Me.MdiChildren(i).Text
frmButton.Tag = i
If MdiChildren(i) Is ActiveMdiChild Then
frmButton.SmallImage = My.Resources.test
End If
windowMenu.Items.Add(frmButton)
AddHandler frmButton.Click, AddressOf frmButton_Click
Next
End Sub
Private Sub frmButton_Click(sender As Object, e As EventArgs)
Dim Rb As C1.Win.C1Ribbon.RibbonButton = DirectCast(sender, C1.Win.C1Ribbon.RibbonButton)
Me.ActivateMdiChild(MdiChildren(CInt(Rb.Tag)))
Me.MdiChildren(CInt(Rb.Tag)).Focus()
End Sub
结束班