Notifications
Clear all

[Closed] addeventhandler "ToolStripMenuItem"

Hey there,

I seem to have run into an odd problem with some MXS dotNet stuff.
I’ve created a ContextMenuStrip for a ListView wich works like a charm, both are dotNetControls of course and the standart MXS way of event handling also works… for the ContextMenuStrip…
The problem I’m having is with the ToolStripMenuItem. I can’t instanciate it as a dotNetControl because i get an unknown system exception… ohkay i thought ill just go with a dotNetObject and use the dotNet.addEventHandler method to do this… oho “like hell” max thought and didnt play along :argh:

Heres a condensed version of the code so you can see why i needa grab the events from the ToolStripMenuItems:


(
	plugin simpleMod someMod
	name:"Some Mod"
	classID:#(0x7b24ccc2, 0x7828260a)
	version:2
	(
		local ListViewItm = dotNetClass "System.Windows.Forms.ListViewItem"
		local ToolStripItm = dotNetClass "System.Windows.Forms.ToolStripMenuItem"
		local SizeClass = dotNetClass "System.Drawing.Size"
		local ColClass = dotNetClass "System.Drawing.Color"
		
		
		parameters main rollout:params
		(
			slaves type:#nodeTab tabSize:5 tabSizeVariable:true --subAnim:true
		)--END params
		
		
		rollout params "Parameters"
		(
			local addSelSet2SlavesToolStripMenuItem
			local slavesLVRCMenuSep1		
			
			fn updateSlavesLV theLV theSlaves= 
			(
				theLV.Items.Clear()
				local slavesArr = for o in slaves where isValidNode o collect (
					local netO = dotNetObject ListViewItm o.name 1
					netO.tag = dotNetMXSValue o
					netO
				)
				theLV.items.AddRange slavesArr
			)
			
			
			dotNetControl slavesLV "System.Windows.Forms.ListView" width:(params.width-15) height:120 align:#center
				dotNetControl slavesLVRCMenu "System.Windows.Forms.ContextMenuStrip" width:0 height:0
			
			
			on params open do
			(
				--init slavesLV
				slavesLV.ContextMenuStrip = slavesLVRCMenu
				slavesLV.SmallImageList = VMotionDelayCTRLFNs.imgListIcons
				slavesLV.Name = "slavesLV"
				slavesLV.HideSelection = false
				slavesLV.UseCompatibleStateImageBehavior = false
				slavesLV.View = (dotNetClass "System.Windows.Forms.View").SmallIcon
				local windwCol = (colorMan.getColor #window) * 255
				slavesLV.BackColor = ColClass.FromArgb windwCol[1] windwCol[2] windwCol[3]
				local txtCol = (colorMan.getColor #text) * 255
				slavesLV.ForeColor = ColClass.FromArgb txtCol[1] txtCol[2] txtCol[3]
				
				
				--init slavesLVRCMenu
				slavesLVRCMenuSep1 = dotNetObject "System.Windows.Forms.ToolStripSeparator" 
				
				addSelSet2SlavesToolStripMenuItem = dotNetObject ToolStripItm "Add Selection Set"
					addSelSet2SlavesToolStripMenuItem.Name = "addSelSet"
						addSelSet2SlavesToolStripMenuItem.ToolTipText = "Adds the selected Selection Set to the Slaves"
						addSelSet2SlavesToolStripMenuItem.DropDownItems.Add (dotNetObject ToolStripItm "None found")
				
				slavesLVRCMenu.Items.AddRange #(slavesLVRCMenuSep1, addSelSet2SlavesToolStripMenuItem)
				slavesLVRCMenu.Name = "slavesLVRCMenu";
				
				
				updateSlavesLV slavesLV slaves
			)--END params.open
			
			
			on slavesLVRCMenu Opening sender args do
			(
				addSelSet2SlavesToolStripMenuItem.DropDownItems.Clear()
				
				if selectionSets.count > 0 then
				(
					for i = 1 to selectionSets.count collect 
					(
						local itm = dotNetObject "System.Windows.Forms.ToolStripMenuItem" -- selectionSets[i].name
						itm.name = itm.text = selectionSets[i].name
						
						fn testThis sender args = 
						(
							format "sender:% e:%
" sender args
						)
						
						addSelSet2SlavesToolStripMenuItem.DropDownItems.Add itm	
						showEvents itm
						dotnet.addeventhandler itm "Click" testThis
					)
				)
				else
				(
					addSelSet2SlavesToolStripMenuItem.DropDownItems.Add (dotNetObject ToolStripItm "None found")
				)
			)--END slavesLVRCMenu.Opening
			
		)--END RO
		
		
	)--END plugin 

)

If someOne knows whats going on :shrug: help would be greatly appreciated.

1 Reply
 lo1

I remember a recent thread about paramblocks and dotnet events, and why they hate each other, but can’t find it now.