Ok, thanks to ILSpy, I know that the MenuItem class contains an internal class named MenuItemData, which contains itself an internal member named onDrawItem.
Given a MenuItem, I want to retrieve the object corresponding to the member onDrawItem. But all I manage to do is to get the FieldInfo, not the object itself.
Here is my code:
Dim obj As Object
Dim fi As FieldInfo
Dim item as System.Windows.Forms.MenuItem
Dim mType As System.Type
mType = item.GetType()
mType = mType.GetMember("MenuItemData", BindingFlags.NonPublic)(0)
fi = mType.GetField("onDrawItem", BindingFlags.Static Or BindingFlags.Instance Or BindingFlags.NonPublic)
obj = fi.GetValue(item)
When reaching the last line, I get an error saying something like that (it's traduced):
The field 'onDrawItem' défined in type 'System.Windows.Forms.MenuItem+MenuItemData' is not a field of the target object of type 'System.Windows.Forms.MenuItem
I don't know what object to pass to the GetValue function on the last line. Any clue?
----EDIT----
My goal is to remove the base eventHandler of the menuItem, named DrawItem. See this post and the function RemoveClickEvent
in the accepted answer for a better understanding.