我需要制作一个滚动字幕类型的消息,显示在文本框中,该消息可自定义,并可通过 Powershell 脚本发出。我试了又试,但无济于事……我已经让它在输出框中滚动,但似乎无法将其放入文本框中……请帮忙!
$s=' '*80+(read-host)+' '*80;for(){write-host($s.Substring(($i=++$i%($s.length-80)),80)+"`r")-N -F R -B 0;sleep -m 99}
答案1
继续我的评论和我发布的搜索链接:前几次点击:
https://devblogs.microsoft.com/scripting/weekend-scripter-using-windows-powershell-to-make-a-marquee
对于 Winform - 您可以转换或按原样使用 C# 选项:
您发布的代码示例与此处发布的代码示例相同:
https://codegolf.stackexchange.com/questions/58732/make-me-a-scrolling-marquee
总而言之,这只是将文本写入文本框、清除该文本并再次写入的问题。同样,对此用例进行简单搜索即可看到这一点。
通过 PowerShell 的图形 Windows 窗体检索状态
https://mcpmag.com/articles/2014/02/04/powershell-graphical-windows-form.aspx
Add-Type -assembly System.Windows.Forms
$form1 = New-Object System.Windows.Forms.Form
$path = 'D:\Temp'
$Title = "Directory Usage Analysis: $Path"
$height = 100
$width = 400
$color = 'White'
$form1.Text = $title
$form1.Height = $height
$form1.Width = $width
$form1.BackColor = $color
$form1.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$label1 = New-Object system.Windows.Forms.Label
$label1.Text = 'not started'
$label1.Left = 5
$label1.Top = 10
$label1.Width = $width - 20
$label1.Height = 50
$label1.Font= 'Verdana'
$form1.controls.add($label1)
$form1.Show() |
out-null
$form1.Focus() |
out-null
$label1.text = "Preparing to analyze $path"
$form1.Refresh()
start-sleep -Seconds 1
$top = Get-ChildItem -Path $path -Directory
foreach ($folder in $top)
{
$label1.text = "Measuring size: $($folder.Name)"
$form1.Refresh()
start-sleep -Milliseconds 100
$stats = Get-ChildItem -path $folder -Recurse -File |
Measure-Object -Property Length -Sum -Average
[pscustomobject]@{
Path = $folder.Name
Files = $stats.count
SizeKB = [math]::Round($stats.sum/1KB,2)
Avg = [math]::Round($stats.average,2)
}
}
$form1.Close()
上面的代码可以轻松调整滚动消息,其方式与显示的目录非常相似。只需读取消息文本,而不是目录。