ross13
asked on
Delegate error “Error binding to target method.”
Hi,
I was wondering if someone is able to help. Please refer to the attached code snippet.
I have created a sub that populates a screen with panels. It is my intention that when a panel is clicked the following method is triggered “PanelClick”.
This method is located within the objSenderForm object that I pass through. I have confirmed during runtime that this can be triggered correctly by doing the following in the immediate window:
DirectCast(objSenderForm,P DM.frmLoad Form).Pane lClick
PanelClick is set to only return a message box and I can confirm that this functions correctly.
The issue is that I receive the following error message “Error binding to target method.” When the following line is being executed:
Dim obj_event_delegate As [Delegate] = [Delegate].CreateDelegate( obj_event_ info.Event HandlerTyp e, DirectCast(objSenderForm, PDM.frmLoadForm), strHandler)
I am unsure how to resolve this issue.
The target is the same as the passed in object that the controls are being added and the strEvent is = to “MouseClick” and the handler is = “PanelClick” which is a public method within frmLoadForm (the passed in object).
Any help would be appreciated. I have possibly just been looking at this too long.
Regards,
Ross
I was wondering if someone is able to help. Please refer to the attached code snippet.
I have created a sub that populates a screen with panels. It is my intention that when a panel is clicked the following method is triggered “PanelClick”.
This method is located within the objSenderForm object that I pass through. I have confirmed during runtime that this can be triggered correctly by doing the following in the immediate window:
DirectCast(objSenderForm,P
PanelClick is set to only return a message box and I can confirm that this functions correctly.
The issue is that I receive the following error message “Error binding to target method.” When the following line is being executed:
Dim obj_event_delegate As [Delegate] = [Delegate].CreateDelegate(
I am unsure how to resolve this issue.
The target is the same as the passed in object that the controls are being added and the strEvent is = to “MouseClick” and the handler is = “PanelClick” which is a public method within frmLoadForm (the passed in object).
Any help would be appreciated. I have possibly just been looking at this too long.
Regards,
Ross
Public Sub getNewPanel(ByVal xCord As Integer, ByVal yCord As Integer, _
ByVal height As Integer, ByVal width As Integer, _
ByVal strEvent As String, ByVal strHandler As String, _
ByVal strQuestion As String, ByVal strControl As String, _
ByVal strContronName As String, ByVal strSendTo As String, _
ByVal booEnabled As Boolean, _
ByVal objSenderForm As Object)
objPanel = New Panel
objPanel.Height = height
objPanel.Width = width
objPanel.Text = ""
objPanel.BackColor = Color.Blue
objPanel.Name = strContronName
objPanel.Enabled = booEnabled
objPanel.Location = New System.Drawing.Point(xCord, yCord)
DirectCast(objSenderForm, PDM.frmLoadForm).Controls.Add(objPanel)
If strHandler <> "" Then
Dim obj_type = objPanel.GetType
Dim obj_event_info = obj_type.GetEvent(strEvent, Reflection.BindingFlags.Instance Or Reflection.BindingFlags.Public)
Dim obj_event_delegate As [Delegate] = [Delegate].CreateDelegate(obj_event_info.EventHandlerType, DirectCast(objSenderForm, PDM.frmLoadForm), strHandler)
'objSenderForm
'DirectCast(Me.objSenderForm,PDM.frmLoadForm)
obj_event_info.AddEventHandler(objPanel, obj_event_delegate)
obj_event_delegate = Nothing
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.