Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winforms 为搜索功能创建进度条_Winforms_Powershell - Fatal编程技术网

Winforms 为搜索功能创建进度条

Winforms 为搜索功能创建进度条,winforms,powershell,Winforms,Powershell,我试图在powershell生成的GUI中创建一个进度条,当系统缓存AD中的所有组时,该进度条将显示搜索的进度(大约有12000个组,否则会导致系统挂起一小段时间) 我设法建立了酒吧等,但我不能让它填补酒吧作为系统添加组。以下是我到目前为止的情况: [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null [reflection.assembly]::loadwithpartialname("Sys

我试图在powershell生成的GUI中创建一个进度条,当系统缓存AD中的所有组时,该进度条将显示搜索的进度(大约有12000个组,否则会导致系统挂起一小段时间)

我设法建立了酒吧等,但我不能让它填补酒吧作为系统添加组。以下是我到目前为止的情况:

[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null

$Form = New-Object System.Windows.Forms.Form
$Form.width = 345
$Form.height = 345
$Form.StartPosition = "CenterScreen"
$Form.ShowInTaskbar = $True
$Form.FormBorderStyle = 'FixedToolWindow'

$ExitButt = new-object System.Windows.Forms.Button
$ExitButt.Location = new-object System.Drawing.Size(235,5)
$ExitButt.Size = new-object System.Drawing.Size(100,20)
$ExitButt.Text = "Exit"
$Form.Controls.Add($ExitButt)
$ExitButt.Add_Click({$Form.Close()})

$Prog = New-Object System.Windows.Forms.ProgressBar
$Prog.Maximum = 10000
$Prog.Minimum = 0
$Prog.Location = new-object System.Drawing.Size(50,50)
$Prog.size = new-object System.Drawing.Size(100,50)
$Form.Controls.Add($Prog)

$Button = new-object System.Windows.Forms.Button
$Button.Location = new-object System.Drawing.Size(120,100)
$Button.Size = new-object System.Drawing.Size(100,30)
$Button.Text = "Start Progress"
$Form.Controls.Add($Button)
$Button.add_click(
    {
    $GroupsList = Get-ADGroup -Server "server" -Filter *
    $Count = ($GroupsList | Measure-Object).Count
    $prog.Value = $Count
    }
    )
$form.ShowDialog() | Out-Null

要更新WinForms
ProgressBar
,只需设置其
属性

例如


将其设置为一半。

您在哪里更新进度条的状态?(必须这样做,它不会自动发生)。我想这就是我正在努力的地方,我正在尝试将物理计数放入一个变量中,然后将进度与该变量相匹配。我可以制作一个没有问题的计时器,但它试图使用计数来代替计时器。我稍微编辑了脚本(参见OP),但问题是它在得到最终计数之前什么都不做,然后在一次跳转中填充条问题是,我希望它随着shell找到的组数的增加而增加该值(因此它看起来像典型的加载条)@Sean您需要找到一个事件(或其他东西),允许您查看流程中的增量步骤。如果它是一个没有任何此类进度数据的黑盒子,那么你就不走运了(只有当你有进度要显示时,你才能显示进度)。还请记住,如果阻止GUI线程,则不会显示UI更新。
# Initialisation...
$myProgBar.Minimum = 1;
$myProgBar.Maximum = 100;

# When something happens...
$myProgBar.Value = 50;