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.
contextmenustrip opening event question
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: contextmenustrip opening event question
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:
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?For your convenience, when you drop a ContextMenuStrip in the designer, PrimalForms will automatically assign the ContextMenuStrip to any control you drop it on.