如何知道winform的名称。事件会触发脚本块?
我构建了一个pswinform构建器,
每个事件在$ threadeventhandler列表中都有一个scriptblock,它们被命名为control.name.name -event.name.name
。
$ThreadEventHandler["Button1-Click"] = [ScriptBlock]{...}
当我在controler.event
上添加简单的ScriptBlock时,没关系。
但是对于较慢的脚本block,我希望该事件使用 start -threadjob whit scriptblock nater control.name-event.name.name
在事件中,我使用$ $ this.name 对于
control.name
,并且我没有向$ thisevent.name
提供
$Form.Button1.Add_Click({
Start-ThreadJob -ScriptBlock $ThreadEventHandler["$($this.Name)-$($ThisEvent.Name)"]
})
transmit $ thisevent.name
的想法事件scriptblock?
I construct a PSWinForm-Builder,
Each event has a Scriptblock in a list of $ThreadEventHandler they are named Control.Name - Event.Name
.
$ThreadEventHandler["Button1-Click"] = [ScriptBlock]{...}
when i add simple scriptblock on controler.event
it is ok.
But for slower scriptblock i want the event use Start-ThreadJob whit scriptblock named Control.Name - Event.Name
, in event I use $this.Name
for Control.Name
and i haven't acces to $ThisEvent.Name
$Form.Button1.Add_Click({
Start-ThreadJob -ScriptBlock $ThreadEventHandler["$($this.Name)-$($ThisEvent.Name)"]
})
Have you an idea for transmit $ThisEvent.Name
in Event ScriptBlock ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基于指向源代码的链接,我建议通过
[scriptblock] :: create()
而不是使用script-block literal来创建您的脚本块。 ({...}
),因为这使您可以“烘烤”$ evt
变量,其中包含事件名称到脚本块中;请注意,如何将NOM 不应该扩展的变量引用(interpolated)提前扩展(Interpolated)将其$
Sigil逃脱为`$
。Based on the link to your source code, I suggest creating your script block from an expandable (here-)string via
[scriptblock]::Create()
instead of using a script-block literal ({ ... }
), as that allows you to "bake" the value of the$Evt
variable containing the event name into the script block; note how the variable references that should not be expanded (interpolated) up front have their$
sigil escaped as`$
.