Notifications
Clear all

[Closed] ContextMenuStrip events in Custom Attributes?

How to add events to ContextMenuStrip when it is in custom attributes definition?
When I use this code to create a dialog, when You click on first item in Contex Menu everything is working fine.


   try(destroydialog roll_type)catch()
   rollout roll_type "" width:131 height:29
   (
   	local arrFavtmp = #("Key Selected", "Key All", "Delete Selected Keys", "Delete All Keys", "Mirror")
   	fn OmniFn sender args = print "Test"
   
   	button btn "Menu"
   	on btn pressed do
   	(
   		(
   			cursor = dotnetclass "System.Windows.Forms.Cursor"
   			p = cursor.Position
   			
   			contextMenu = dotNetObject "System.Windows.Forms.ContextMenuStrip"
   			contexSep = dotNetObject "System.Windows.Forms.ToolStripSeparator"
   			contexSep2 = dotNetObject "System.Windows.Forms.ToolStripSeparator"
   			
   			contextMenu.Items.Add(arrFavtmp[1])
   			contextMenu.Items.Add(arrFavtmp[2])
   			contextMenu.Items.Add contexSep
   			contextMenu.Items.Add(arrFavtmp[3])
   			contextMenu.Items.Add(arrFavtmp[4])
   			contextMenu.Items.Add contexSep2
   			contextMenu.Items.Add(arrFavtmp[5])
   			
   			contextmenu.Show p.x (p.y+5)
   			dotnet.addeventhandler contextMenu.Items.item[0] "Click" OmniFn
   		)
   	)
   )
   createdialog roll_type
   
   

But when I add this to custom attributes nothing it is not working.


   pt=point()
   addModifier pt (EmptyModifier()) 
   ca = attributes dotRcMenu 
   ( 
   	rollout roll_type "" width:131 height:29
   	(
   		local arrFavtmp = #("Key Selected", "Key All", "Delete Selected Keys", "Delete All Keys", "Mirror")
   		fn OmniFn sender args = print "Test"
   
   		button btn "Menu"
   		on btn pressed do
   		(
   			(
   				cursor = dotnetclass "System.Windows.Forms.Cursor"
   				p = cursor.Position
   				
   				contextMenu = dotNetObject "System.Windows.Forms.ContextMenuStrip"
   				contexSep = dotNetObject "System.Windows.Forms.ToolStripSeparator"
   				contexSep2 = dotNetObject "System.Windows.Forms.ToolStripSeparator"
   				
   				contextMenu.Items.Add(arrFavtmp[1])
   				contextMenu.Items.Add(arrFavtmp[2])
   				contextMenu.Items.Add contexSep
   				contextMenu.Items.Add(arrFavtmp[3])
   				contextMenu.Items.Add(arrFavtmp[4])
   				contextMenu.Items.Add contexSep2
   				contextMenu.Items.Add(arrFavtmp[5])
   				
   				contextmenu.Show p.x (p.y+5)
   				dotnet.addeventhandler contextMenu.Items.item[0] "Click" OmniFn
   			)
   		)
   	)
   )
   custAttributes.add pt.modifiers[1] ca 
   
4 Replies
 PEN

I don’t think this is going to work for you. It appears as though the modifier panel is in some strange scope, even with scripted modifiers and objects you can’t get event handlers to fire. Since a CA def is the same thing as a scripted plugin it will also not work.

Thanks, for answer Paul.
So I will have to use simple mxs rcMenu instead of ContextMenuStrip.

 PEN

Yep, I have run into this many times.

ContextMenuStrip appears to be a top level control and probably event handler have to be defined in matching top level scope. Like this:

(
       	
       fn OmniFn sender args = messagebox "Sitting On Top Of The World"
       			
       	local arrFavtmp = #("Key Selected", "Key All", "Delete Selected Keys", "Delete All Keys","Mirror")
       		
       	contextMenu = dotNetObject "System.Windows.Forms.ContextMenuStrip"
       	local contexSep = dotNetObject "System.Windows.Forms.ToolStripSeparator"
       	local contexSep2 = dotNetObject "System.Windows.Forms.ToolStripSeparator"
       	
       	contextMenu.Items.Add(arrFavtmp[1])
       	contextMenu.Items.Add(arrFavtmp[2])
       	contextMenu.Items.Add contexSep
       	contextMenu.Items.Add(arrFavtmp[3])
       	contextMenu.Items.Add(arrFavtmp[4])
       	contextMenu.Items.Add contexSep2
       	contextMenu.Items.Add(arrFavtmp[5])
       			
       	dotnet.addeventhandler contextMenu.Items.item[0] "Click" OmniFn
       	
          pt=point()
          addModifier pt (EmptyModifier()) 
          ca = attributes dotRcMenu 
          (
       	   rollout roll_type "" width:131 height:29
       	   (
       		   button btn "Menu"
       		   on btn pressed do
       		   (
       			   (
       				   cursor = dotnetclass "System.Windows.Forms.Cursor"
       				   p = cursor.Position
       				   contextmenu.Show p.x (p.y+5)
       			   )
       		   )
       	   )
          )
          custAttributes.add pt.modifiers[1] ca 
          )
  It might not be very usefull but event handler fires.
  Maybe try MenuStrip instead, it can be added to the Form.