I have a customized Collection which is sometimes used during Designtime.
The cutomized classes which I want to add (and also remove) to the classes have Events which should be collected in my Collection and also given to outside of this collection.
If I work with the Runtime-part everything works like I want because my Add- and my Remove-Methods could add and remove the Handlers.
During Designtime I supposed that the method OnInsertComplete is called when pressing the Add-Button of the Editor - this works indirectly.
Also I supposed that the method OnRemove or OnRemoveComplete is called when pressing the Remove-Button of the Editor - but this never happens.
So I thought about a work-around which catches the method-delegate of the Click-Event of the Remove-Button, Remove this Delegate from the Button and replace it with my own method which calls the OnRemove on the Collection, call the saved Delegate and after that call the OnRemoveComplete of the Collection.
And this is the point where I stuck.
I can get the Eventinfo from the Button, I can make a MethodInfo ... but I can't get a Delegate from it.
What I have tried:
Public Class RMCollectionEditor
Inherits CollectionEditor
Public Sub New(ByVal type As System.Type)
MyBase.New(type)
End Sub
Protected Overrides Function CreateCollectionForm() As CollectionEditor.CollectionForm
Dim cForm As CollectionForm = MyBase.CreateCollectionForm()
Dim myButton() As Control
myButton = cForm.Controls.Find("removeButton", True)
If myButton.Length > 0 Then
Dim myEventInfo As System.Reflection.EventInfo = GetType(Button).GetEvent("Click", Reflection.BindingFlags.NonPublic Or BindingFlags.Public Or Reflection.BindingFlags.Instance)
Dim myInfo As System.Reflection.MethodInfo = myEventInfo.GetAddMethod(True)
RepeatDelegate = [Delegate].CreateDelegate(GetType(delegate_OnClick), myInfo, False)
RemoveHandler myButton(0).Click, [Delegate].CreateDelegate(GetType(delegate_OnClick), myInfo, False)
AddHandler myButton(0).Click, AddressOf RemoveButton_Handler
End If
Return cForm
End Function
Private Sub RemoveButton_Handler(sender As Object, e As EventArgs)
MessageBox.Show("Remove")
End Sub
End Class
It would be nice if someone could help me to get the next step ...