View Full Version : dotNET menu's broken
05-16-2008, 08:33 PM
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.
05-18-2008, 04:17 PM
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.
--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
--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
--defining the menuitems
theMenu = dotNetObject "menustrip"
submenuItemArray0 = #("load material library")
submenuItemArray1 = #("test1")
----adding the menuitems
fn_initMenuDropDownItems (theMenu.items.item) submenuItemArray0
fn_initMenuDropDownItems (theMenu.items.item) 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
function fn_diagnoseButton control arg =
function fn_importSingleToSlot control arg =
dotNet.addEventHandler btnTest "click" fn_diagnoseButton
dotNet.addEventHandler btnLoad "click" fn_importSingleToSlot
dotNet.addEventHandler theMenu.items.item.dropDownItems.item "click" fn_importSingleToSlot
dotNet.addEventHandler theMenu.items.item.dropDownItems.item "click" fn_diagnoseButton
frmNewAsset = dotNetObject "Form" --the form in which the controls are placed
frmNewAsset.Size = dotNetObject "System.Drawing.Size" 200 170
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?
05-20-2008, 07:21 AM
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 =
--the actual handler added to a menuItem
dotNet.addEventHandler theMenu.items.item.dropDownItems.item "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?
05-20-2008, 07:21 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.