-
Dynamic menus
Hi,
I'm writing a VB.NET component dll to dynamically build menus from a database. This functions fine. A form contains the menu, and I assume should also contain the delegate event handler to handle the clicks on the dynamic menu and then call the component dll again sending which menu item was clicked. My problem is this... how do I assign the delegate as the handler for all the menu items created in the dll? So far I've assumed that I could pass the delegate as an object and use the AddressOf() function during the MenuItems.Add() to assign the delegate as the event handler. Any help would be appreciated.
Adrian
-
It will look something like the following pseudo-code
Code:
Dim menuItem as new MenuItem()
'your code here
AddHandler(address of 'delegate here)
Menu.Add(menuItem)
-
thanx
Thank you for your timely response.
The code you mentioned to AddHandler will be in the dll and the delegate sub which will be referenced in this dll code example will be in a separate form that calls the dll. Do you know how I can pass this delegate or reference to it, to the dll?
-
you could pass the delegate as any other type.
(I dont know if i understood your question correctly)
-
clarification
Yeah it's pretty hard to get my point across. I'll try a code example.
Form Code:
---------------
Call privObjUVConnection.LoadDynamicMenu(strExe, "frm3200", frmMain.mnuMain, frmMain)
sub MenuHandler()...
DLL Code:
-------------
Public Sub LoadDynamicMenu(ByVal strEXEName As String, ByVal strFormName As String, ByVal mnuMenu As Menu, ByVal frmForm As Object)
mnuItems(intCnt) = New MenuItem(strMenuCaption, New System.EventHandler(AddressOf frmForm.MenuHandler))
Points:
---------
I'd like to reference MenuHandler() in the dll using the AddressOf() function to describe it as THE event handler for all dynamically created menus. No matter how I try, I get errors in the IDE stating it cant make the reference. This dll code needs to be reusable from any form that calls it.
I'm not sure if I'm doing this the right way, or I'm missing something. I'm expecting that I cant pass over a reference/pointer or object that the dll can resolve the MenuHandler subroutine and apply it as the generic EventHandler so that the calling form will automatically call the dll with an index when a menu is clicked.
Thanks for your time.
:confused:
-
Hi.
Why not have the delegate in the DLL?
You could add the handler to a sub inside the dll, and raise an event from there. All the user has to do is dim the dll withevents.
-
Done, thanx
Menus now working. Thank you fo the support.
Adrian :bigyello: