Page 1 of 1

contextmenustrip opening event question

Posted: Wed Feb 10, 2016 1:12 am
by tbednarz
I added a contextmenustrip control zu a form created with PowerShell Studio 2015. This form has TabControls and within the tabs many other controls. The context menu appears everywhere when I right-click with the mouse!

So I implemented the event contextmenustrip_Opening and set $_.Cancel = $true. The result is that it does not appear anywhere. I try to figure out, where the user clicked but that seems to be hard.... I did:

$control = $contextmenustrip1.SourceControl

$control contains always System.Windows.Forms.TabControl, TabPages.Count: 3, ..... etc, whatever the toString method returns. I rather would expect something like treecontrol1 or GridListView1 etc. How do I get this information? In the Opening Event I like to build a context menu depending on the control where the user clicked.

Re: contextmenustrip opening event question

Posted: Wed Feb 10, 2016 2:10 am
by jvierra
Attach context menu to the control you need it to apply to. You have attached it to the main form so it will open everywhere.

Re: contextmenustrip opening event question

Posted: Wed Feb 10, 2016 2:23 am
by tbednarz
Hmm I am probably too stupid, but when I drag it in the designer, it is sort of everywhere. In the following article (https://www.sapien.com/blog/2011/12/16/ ... p-control/) is written:
For your convenience, when you drop a ContextMenuStrip in the designer, PrimalForms will automatically assign the ContextMenuStrip to any control you drop it on.
So I have set the property 'ContextMenuStrip' of the datagridview where I like to show it up to 'contextmenustrip1'. But it still shows up everywhere.... Does it mean I have to create it manually e.g. on FormLoad WITHOUT the designer and then assign it to the mentioned propertiy?

Re: contextmenustrip opening event question

Posted: Wed Feb 10, 2016 2:42 am
by jvierra
Go to properties of the control you want to use this on and select "ContextMenu" property and set it to the menu you want.