Home > Software engineering >  creating a System.Windows.Forms.Textbox that would accept array input
creating a System.Windows.Forms.Textbox that would accept array input

Time:01-21

i'm looking for help in creating a System.Windows.Forms.Textbox that would accept array input and treat it as an array input, rn textbox properties looks something like this:

$boxname.AcceptsReturn = $true

$boxname.MultiLine = $true

$boxname.Autosize = $true

$boxname.AcceptsTab = $false

$boxname.Scrollbars = 'Vertical'

If i enter multiline paths like this:

C:\Windows

C:\Program Files

C:\Temp

$boxname.text is treated like one huge string and won't let my "test-path on each item in array" function work properly, i bound it to this box with .Add_TextChanged, what i'm trying to do is to create a box, that will perform a check that entered paths exist once the box is filled.

Is this even possible without additional parsing ? Maybe i'm missing something.

CodePudding user response:

You need to split the multiline text into separate lines and then loop over these lines to do your checks.

$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!"
        }
    }
})
  •  Tags:  
  • Related