powershell - 如何让发件人在 Powershell 表单中使用鼠标右键单击菜单
问题描述
我使用动态标签。我需要知道在哪个动态标签上按下了右键。当我双击服务器名称时,它会写下我按下的标签。但是我怎样才能得到我按下的标签ContextMenuStrip
?
这是我的脚本的相关部分:
$contextMenuStrip1 = New-Object System.Windows.Forms.ContextMenuStrip
$Menu1a = $contextMenuStrip1.Items.Add("Item 1")
$Menu1a.add_Click(
{
param($Sender,$EventArgs) write-host $Sender.name
Write-Host $this.Text
})
$Menu1b = $contextMenuStrip1.Items.Add("Item 2")
$Menu1b.add_Click({Write-Host $this.Text})
$Global:DynLblElemCol1 = foreach($Server in $Servers)
{
$Col = New-Object System.Windows.Forms.Label
$Col.Size = New-Object System.Drawing.Size(100, 18)
$col.TextAlign = "MiddleCenter"
$col.Text = $Server
$Col.Name = $Server
$Col.Add_DoubleClick({param($Sender,$EventArgs) write-host $Sender.Text})
$Col.ContextMenuStrip = $contextMenuStrip1
$Col
}
foreach($item in $DynLblElemCol1)
{
$item.Location = New-Object System.Drawing.Point(80, $CheckBoxCounter)
$Form1.Controls.Add($item)
$CheckBoxCounter = $item.Bottom + $LineSpace # increment our counter
}
}
解决方案
推荐阅读
- mysql - 在MYSQL中用空格分割字符串
- asp.net-core - 如何在 ASP.NET Core 3.1 中重新加载动态配置的重写选项
- python - 如何在 tkinter 文本框中使用带有 html 标签的文本,或更改它以使其在 tkinter 标签中工作?
- javascript - 重叠元素中的 onClick 事件传播
- python - pandas 使用 groupby 和基于值的过滤器
- python - 在python(使用bs4)中跨多个非统一表返回数据的一次迭代?
- ruby-on-rails - Rails 服务器在开发模式下工作,但不在生产模式下
- javascript - 简单的 Web 脚本无休止地运行,而不是只运行一次
- sharepoint-online - Microsoft Graph API:更新 DocumentLibrary 中文件元数据的 PATCH 导致 409 响应;代码:resourceModified
- sql - Oracle SQL 多列 <> 空选择