小编Tec*_*hno的帖子

在 Powershell 中,成功复制文件后如何更改标签文本?

我开始构建一个带有“复制”按钮和该按钮下的标签的小型 winform。\n当我单击“复制”按钮时,它开始将文件从源复制到目标。\n我想异步运行此操作,因此我不希望表单复制操作运行时被冻结。这就是我使用 Job 的原因。成功复制后,我需要复制反馈并显示绿色的“OK”文本,但它不起作用。

\n

这是我的代码:

\n
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")\n[System.Windows.Forms.Application]::EnableVisualStyles()\n\nFunction Copy-Action{\n\n    $Computername = "testclient"\n\n    $Source_Path = "C:\\temp\\"\n    $Destination_Path = "\\\\$Computername\\c$\\temp"\n\n\n    $job = Start-Job -Name "Copy" -ArgumentList $Source_Path,$Destination_Path \xe2\x80\x93ScriptBlock {\n           param($Source_Path,$Destination_Path) \n                    \n           Copy-Item $Source_Path -Destination $Destination_Path -Recurse -Force\n            \n            } \n \n    Register-ObjectEvent $job StateChanged -MessageData $Status_Label -Action {\n        [Console]::Beep(1000,500)\n        $Status_Label.Text = "OK"\n        $Status_Label.ForeColor = "#009900"\n        $eventSubscriber | Unregister-Event\n        $eventSubscriber.Action | Remove-Job\n        } | Out-Null\n}\n\n# DRAW FORM\n$form_MainForm = New-Object System.Windows.Forms.Form\n$form_MainForm.Text = "Test Copy"\n$form_MainForm.Size = New-Object System.Drawing.Size(200,200)\n$form_MainForm.FormBorderStyle = "FixedDialog"\n$form_MainForm.StartPosition = "CenterScreen"\n$form_MainForm.MaximizeBox …
Run Code Online (Sandbox Code Playgroud)

powershell winforms

2
推荐指数
1
解决办法
2500
查看次数

标签 统计

powershell ×1

winforms ×1