' EditorWithCombo 変数を宣言します。
Private editor As EditorWithCombo = Nothing
' UltraTree コントロールの AfterActivate イベントを処理して、ActiveNode に関連付けられた EditorWithCombo の SelectionChanged イベントを発生させます。
Private Sub ultraTree1_AfterActivate(ByVal sender As Object, ByVal e As NodeEventArgs) Handles ultraTree1. AfterActivate
Dim node As UltraTreeNode = e.TreeNode
If node Is Nothing Then
Exit Sub
End If
Dim editor_Combo As EditorWithCombo = TryCast(node.EditorResolved, EditorWithCombo)
' 前回エディタを変更して以降エディタが変更されていない場合には、正しいエディタのイベントをすでにリッスンしているので戻ります。
If Me.editor = editor_Combo Then
Exit Sub
End If
' 非 null エディタ 参照がある場合には、SelectionChanged イベントのフックを解除します。
' (以前の選択が異なるエディタだった場合にこのループが実行されます。)
If Me.editor IsNot Nothing Then
RemoveHandler Me.editor.SelectionChanged, AddressOf Me.editor_SelectionChanged
Me.editor = Nothing
End If
' 参照を設定します。
Me.editor = editor_Combo
' 新しいエディタでイベントを接続します。
AddHandler Me.editor.SelectionChanged, AddressOf Me.editor_SelectionChanged
End Sub
' EditorWithCombo の SelectionChanged イベントを処理します。
Private Sub editor_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles editor.SelectionChanged
Dim editor As EditorWithCombo = TryCast(sender, EditorWithCombo)
Dim val As Object = editor.Value
End Sub