[Closed] dotNET menu's broken
Hi,
i’ve created a script with a dotNET interface. The interface uses a toolstrip menu. I’ve added a copy/paste version of pieces of my script. In my script the menu doesn’t respond anymore after loading in a materiallibrary. Kind of weird. My example executes the loading of the matlib also from a menuItem, but i also had the problem when loading by doubleclicking a listview item.
Could someone reproduce the error with my script and preferrably solve my problem? I’m at a loss.
Klaas
Well, maybe i should give a bit more information.
This script uses a full dotNet interface with a menu at the top. There are several menuItems performing different tasks. This functions great and looks good too! There's one task however which bothers me. It's when i load a material library, either from a menuItem or a button. After loading any library, my menu doesn't respond anymore. I can click all i want but the menuItems don't do anything.
--MENUSTRIP STUFF
--add items to the menustrip
function fn_initMenuItems theMenu =
(
theItemArray = #("load","test")
for o in theItemArray do
(
theItem = dotNetObject "System.Windows.Forms.ToolStripMenuItem"
theItem.text = o
theMenu.items.add theItem
)
)
--add subitems to the menustripitems
function fn_initMenuDropDownItems parent Items =
(
theSubItemArray = #()
for o in Items do
(
theSubItem = dotNetObject "System.Windows.Forms.ToolStripMenuItem"
theSubItem.text = o
parent.Dropdownitems.add theSubitem
)
)
--defining the menuitems
theMenu = dotNetObject "menustrip"
submenuItemArray0 = #("load material library")
submenuItemArray1 = #("test1")
----adding the menuitems
fn_initMenuItems theMenu
fn_initMenuDropDownItems (theMenu.items.item[0]) submenuItemArray0
fn_initMenuDropDownItems (theMenu.items.item[1]) submenuItemArray1
--OTHER CONTROL DEFINITION
btnTest = dotNetObject "button"
btnTest.location = dotNetobject "System.drawing.point" 2 120
btnTest.text = "test4"
btnLoad = dotNetObject "button"
btnLoad.location = dotNetobject "System.drawing.point" 102 120
btnLoad.text = "load"
controlArray = #(btnTest,theMenu,btnLoad) --an array with controls to be added to the form
--EVENT HANDLER FUNCTIONS
--diagnostics
function fn_diagnoseButton control arg =
(
print control.text
)
function fn_importSingleToSlot control arg =
(
fileOpenMatLib()
)
--EVENT HANDLERS
dotNet.addEventHandler btnTest "click" fn_diagnoseButton
dotNet.addEventHandler btnLoad "click" fn_importSingleToSlot
dotNet.addEventHandler theMenu.items.item[0].dropDownItems.item[0] "click" fn_importSingleToSlot
dotNet.addEventHandler theMenu.items.item[1].dropDownItems.item[0] "click" fn_diagnoseButton
--FORM CREATION
frmNewAsset = dotNetObject "Form" --the form in which the controls are placed
frmNewAsset.Size = dotNetObject "System.Drawing.Size" 200 170
frmNewAsset.controls.addRange controlArray
frmNewAsset.show() --show a form
The top of the code creates the menu’s. I also have two buttons. At the end there are two event handler functions: one loads a matlib and the other prints out the text of the control to the listener. That’s to see if the control is still alive.
So my guess is that loading a library maybe shifts the focus or reorders the menuID’s. But i don’t know how to fix or avoid this or if it’s something else. Could somebody help me?
Thanks,
Klaas
Ok,
seems a one man show here...
i've narrowed down the problem a bit. It seems that running some functions in this script removes the eventhandler from the "toolStripMenuItems". I can then add the same eventhandler again and the menu will work as it should. The same functions which break my menu leave my buttons unharmed. So i guess i'm handling my menus wgrongly.Running a function like this
--the eventHandler's function
function fn_loadMatLib control arg =
(
fileOpenMatLib()
)
--the actual handler added to a menuItem
dotNet.addEventHandler theMenu.items.item[0].dropDownItems.item[0] "click" fn_loadMatLib
will remove the handlers from all menuItems. When i add the above handler again to the menuItems, evertything works. Does anyone have experience with this problem or maybe have a solution or point out something i’ve overlooked?
Thanks,
Klaas