如何知道winform的名称。事件会触发脚本块?

发布于 2025-02-13 05:55:17 字数 909 浏览 0 评论 0原文

我构建了一个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?

我在github上的完整代码

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 ?

My Full code on GitHub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒绊 2025-02-20 05:55:17

基于指向源代码的链接,我建议通过[scriptblock] :: create()而不是使用script-block literal来创建您的脚本块。 {...}),因为这使您可以“烘烤” $ evt变量,其中包含事件名称到脚本块中;请注意,如何将NOM 不应该扩展的变量引用(interpolated)提前扩展(Interpolated)将其$ Sigil逃脱为`$

$Script:ControlHandler[$Name]."Add_$($Evt)"(
  [scriptblock]::Create(@"
    param(`$caller, `$e)
    Start-ThreadJob -Name "`$(`$this.Name)-$Evt" -ScriptBlock `$Script:ThreadEventHandler["`$(`$this.Name)-$Evt"].ScriptBlock
"@)
)

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 `$.

$Script:ControlHandler[$Name]."Add_$($Evt)"(
  [scriptblock]::Create(@"
    param(`$caller, `$e)
    Start-ThreadJob -Name "`$(`$this.Name)-$Evt" -ScriptBlock `$Script:ThreadEventHandler["`$(`$this.Name)-$Evt"].ScriptBlock
"@)
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文