创建一个接受数组输入的 System.Windows.Forms.Textbox
creating a System.Windows.Forms.Textbox that would accept array input
我正在寻求帮助来创建一个 System.Windows.Forms.Textbox 来接受数组输入并将其视为数组输入,rn 文本框属性看起来像这样:
$boxname.AcceptsReturn = $true
$boxname.MultiLine = $true
$boxname.Autosize = $true
$boxname.AcceptsTab = $false
$boxname.Scrollbars = 'Vertical'
如果我像这样输入多行路径:
C:\Windows
C:\Program Files
C:\Temp
$boxname.text 被视为一个巨大的字符串,不会让我的“数组中每个项目的测试路径”功能正常工作,我将它绑定到这个框 .Add_TextChanged ,我想要做的是创建一个框,一旦框被填充,它将执行检查是否存在输入的路径。
如果不进行额外的解析,这是否可行?也许我遗漏了什么。
您需要将多行文本拆分成单独的行,然后遍历这些行来进行检查。
$boxname.Add_TextChanged({
# inside the eventhandler, you can refer to the control object itself using automatic variable $this
$this.Text -split '\r?\n' -ne '' | ForEach-Object {
if (-not(Test-Path -Path $_)) {
# path does not exist, do something..
Write-Host "Path '$_' not found!"
}
}
})
我正在寻求帮助来创建一个 System.Windows.Forms.Textbox 来接受数组输入并将其视为数组输入,rn 文本框属性看起来像这样:
$boxname.AcceptsReturn = $true
$boxname.MultiLine = $true
$boxname.Autosize = $true
$boxname.AcceptsTab = $false
$boxname.Scrollbars = 'Vertical'
如果我像这样输入多行路径:
C:\Windows
C:\Program Files
C:\Temp
$boxname.text 被视为一个巨大的字符串,不会让我的“数组中每个项目的测试路径”功能正常工作,我将它绑定到这个框 .Add_TextChanged ,我想要做的是创建一个框,一旦框被填充,它将执行检查是否存在输入的路径。
如果不进行额外的解析,这是否可行?也许我遗漏了什么。
您需要将多行文本拆分成单独的行,然后遍历这些行来进行检查。
$boxname.Add_TextChanged({
# inside the eventhandler, you can refer to the control object itself using automatic variable $this
$this.Text -split '\r?\n' -ne '' | ForEach-Object {
if (-not(Test-Path -Path $_)) {
# path does not exist, do something..
Write-Host "Path '$_' not found!"
}
}
})