Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
In my form I have:

Private Sub AssignMenuHandler
  For Each historyItem In _historyMenu.HistoryItems
    menItem = historyItem.MenuItem
    AddHandler menItem.Click, AddressOf MenuHandler
  Next
End Sub

Public Sub MenuHandler(ByVal sender As Object, ByVal e As EventArgs)
  Dim menuItem As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
  Dim historyItem As String

  historyItem = menuItem.Text .....

But I want to do the asignment in the HistoryMenu class when the historyItem.MenuItems are created. To do that I need something like


Private Sub LoadHistory(ByVal mainMenuItem As ToolStripMenuItem, delegateProcedure as ???)
  Dim menTemp As System.Windows.Forms.ToolStripMenuItem
  Dim menuText As String

  Dim historyItem As HistoryItem
  For Each historyItem In _historyItems
    menTemp = historyItem.MenuItem
    AddHandler menTemp.Click, AddressOf delegateProcedure
  Next
End Sub


How do I declare delegateProcedure? How do I define it in the form? Can it be done?

[edit]Code blocks added - OriginalGriff[/edit]
Posted
Updated 13-Jun-11 4:16am
v2

1 solution

This article demonstrates how to delcare and use delegates in VB.NET:
A Beginner's Guide to Delegates[^].
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900