|
-
Feb 3rd, 2004, 04:26 PM
#1
Thread Starter
New Member
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
-
Feb 3rd, 2004, 04:56 PM
#2
yay gay
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)
\m/  \m/
-
Feb 3rd, 2004, 06:09 PM
#3
Thread Starter
New Member
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?
-
Feb 3rd, 2004, 06:17 PM
#4
yay gay
you could pass the delegate as any other type.
(I dont know if i understood your question correctly)
\m/  \m/
-
Feb 3rd, 2004, 06:57 PM
#5
Thread Starter
New Member
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.
-
Feb 4th, 2004, 12:11 PM
#6
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.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 4th, 2004, 11:49 PM
#7
Thread Starter
New Member
Done, thanx
Menus now working. Thank you fo the support.
Adrian
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|