ContextMenuStrip question

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
Locked
User avatar
Domtar
Posts: 90
Joined: Sun Mar 03, 2013 12:42 pm

ContextMenuStrip question

Post by Domtar »

hi everyone,

in a GUI i'm working on, i would like to use the same ContextMenuStrip that i would associate to a few datagridview to select an item. since it's the same function that is running, it's only logical to use the same strip.

I've created 2 datagridview, associated my strip to each, now i'm trying to understand how to get the calling control.

is there a way to identify the control who called the strip?

thank you!

jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: ContextMenuStrip question

Post by jvierra »

Use the same event for all controls that share the strip. The current control that the strip is associated with is the "$contextmenustrip1.SourceControl"

Example:

Code: Select all

$testToolStripMenuItem_Click={
	Write-Host $contextmenustrip1.SourceControl.Name
}

jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: ContextMenuStrip question

Post by jvierra »

Here is a better example:

Code: Select all

$testToolStripMenuItem_Click={
	Write-Host $this.Name
	Write-Host $contextmenustrip1.SourceControl.Name
}

$testerToolStripMenuItem_Click={
	Write-Host $this.Name
	Write-Host $contextmenustrip1.SourceControl.Name
}

User avatar
Domtar
Posts: 90
Joined: Sun Mar 03, 2013 12:42 pm

Re: ContextMenuStrip question

Post by Domtar »

exactly what i was looking for :-)

thank you J.

Locked