Динамическая обработка события с использованием технологии отображения?
DOpenRealyForms() - массив форм
Private Sub LoadOtherFormDOpenRealyForms(ByVal sender As System.Object, ByVal e As System.EventArgs)
...
End Sub
Так всё работает:
Dim D As EventHandler = AddressOf LoadOtherFormDOpenRealyForms
Dim t As Type = DOpenRealyForms(DOpenRealyForms.GetUpperBound(0)).GetType
Dim Events() As Reflection.EventInfo = t.GetEvents
Dim i As Integer
For i = 0 To Events.Length - 1
If (Events(i).Name = "Click") Then
Events(i).AddEventHandler(DOpenRealyForms(DOpenRealyForms.GetUpperBound(0)), D)
Exit For
End If
А так возникает ошибка "Object type can not be converted to target type." в выделенной строке:
Dim D As EventHandler = AddressOf LoadOtherFormDOpenRealyForms
Dim t As Type = DOpenRealyForms(DOpenRealyForms.GetUpperBound(0)).GetType
Dim Events() As Reflection.EventInfo = t.GetEvents
Dim i As Integer
For i = 0 To Events.Length - 1
If (Events(i).Name = "LoadOtherForm") Then
[B]Events(i).AddEventHandler(DOpenRealyForms(DOpenRealyForms.GetUpperBound(0)), D)[/B]
Exit For
End If
Next i
Ответить
|