我从父表单创建了许多子表单,每个子表单都属于同一类。 每个子窗体都定义一个事件,该事件应导致父窗体创建其他类的新子窗体。 -但是,只有最新创建的子表单可以处理事件。
考虑到这是因为我重用了对子表单的引用,所以将每个子表单存储在类型为子表单的链接列表中。
SubForm代码。
Public Class UserEditor
Property ID As Integer
Public Event EditGroup(ByRef group As GroupPrincipal, ByVal newWindow As Boolean, ByVal Source As Integer)
Public Sub New(ByVal U As UserPrincipal, ByVal theId As Integer)
InitializeComponent()
ID = theId
UserEditor1.DisplayUserPrincipal(U)
End Sub
Private Sub UserEditor1_GroupEdit(ByRef groupItem As GroupListItem) Handles UserEditor1.GroupEdit
RaiseEvent EditGroup(groupItem.Grp, False, ID)
End Sub
父母表格上的代码
Public Class ASADManager
Dim WithEvents UserEditorInstance As UserEditor
Dim WithEvents UserEditorList As New List(Of UserEditor)
此代码在显示的列表中选择叶子对象时触发。
If TypeOf leafObject Is UserPrincipal Then
UserEditorInstance = New UserEditor(currentLeaf.Principal, UserEditorList.Count) With {
.Text = currentLeaf.SamAccountName
}
UserEditorInstance.Show()
UserEditorInstance.Activate()
UserEditorList.Add(UserEditorInstance)
End If
Private Sub EditGroup(ByRef grp As GroupPrincipal, newWindow As Boolean, Source As Integer) Handles UserEditorInstance.EditGroup
If Not newWindow Then
Dim GEdit As New GroupEditorForm(grp) With {
.Text = grp.Name
}
GEdit.Show()
End If
End Sub
在最新打开的UserEditorInstance中,一切正常,它捕获并重新抛出该事件,这是由父级引起的,它打开了GroupEditor表单。
但是,如果我选择第二个LeafObject(打开另一个UserEditor窗口),则会捕获事件,而不是前一个。
我如何同时捕获两者?
希望这种解释可以使我清楚自己在做什么(做错了)