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
Next i
А так:
- Код: Выделить всё
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
Events(i).AddEventHandler(DOpenRealyForms(DOpenRealyForms.GetUpperBound(0)), D)
Exit For
End If
Next i
возникает ошибка "Object type can not be converted to target type." в строке Events(i).AddEventHandler(DOpenRealyForms(DOpenRealyForms.GetUpperBound(0)), D)
Хотя процедура LoadOtherForm существует и выглядит так:
- Код: Выделить всё
Public Event LoadOtherForm(ByVal sender As System.Object, ByVal e As System.EventArgs)
Почему происходит эта ошибка???