Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. VB & delegates

VB & delegates

Scheduled Pinned Locked Moved Visual Basic
wpfwcftestingbeta-testinghelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mr_12345
    wrote on last edited by
    #1

    I am new to using delegates and am getting "Error Binding To Target Method" error on the CreateDelegate line. What am I doing wrong? Thanks in Advance. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim sTest As String = "MyTest" Dim test As ToolStripMenuItem Dim currentType As Type = Me.GetType Dim method As MethodInfo Dim delTest As [Delegate] method = currentType.GetMethod(sTest) If Not method Is Nothing Then MsgBox(method.Name) delTest = CreateDelegate(GetType(EventHandler), method) test = New ToolStripMenuItem("Testing", Nothing, delTest) Else test = New ToolStripMenuItem("Testing") End If MyBase.mnuMain.Items.Add(test) End Sub Public Sub MyTest(ByVal sender As Object, ByVal e As EventArgs) MsgBox("testing") End Sub

    D 1 Reply Last reply
    0
    • M mr_12345

      I am new to using delegates and am getting "Error Binding To Target Method" error on the CreateDelegate line. What am I doing wrong? Thanks in Advance. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim sTest As String = "MyTest" Dim test As ToolStripMenuItem Dim currentType As Type = Me.GetType Dim method As MethodInfo Dim delTest As [Delegate] method = currentType.GetMethod(sTest) If Not method Is Nothing Then MsgBox(method.Name) delTest = CreateDelegate(GetType(EventHandler), method) test = New ToolStripMenuItem("Testing", Nothing, delTest) Else test = New ToolStripMenuItem("Testing") End If MyBase.mnuMain.Items.Add(test) End Sub Public Sub MyTest(ByVal sender As Object, ByVal e As EventArgs) MsgBox("testing") End Sub

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      This isn't working because, for some reason, MyTest's signature doesn't match the signature of EventHandler. You'll run into another problem after that one's fixed. The method you're binding the delegate to must be a Shared method (Static in C#).

      Imports System.Reflection
      Imports System.Delegate
      .
      .
      .
      Public Shared Sub MyTest(ByVal sender As Object, ByVal e As EventArgs)
      MsgBox("Testing...")
      End Sub

      RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        This isn't working because, for some reason, MyTest's signature doesn't match the signature of EventHandler. You'll run into another problem after that one's fixed. The method you're binding the delegate to must be a Shared method (Static in C#).

        Imports System.Reflection
        Imports System.Delegate
        .
        .
        .
        Public Shared Sub MyTest(ByVal sender As Object, ByVal e As EventArgs)
        MsgBox("Testing...")
        End Sub

        RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        M Offline
        M Offline
        mr_12345
        wrote on last edited by
        #3

        Thanks.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups