如何限制 TextBox 中的行数并将行拆分为字符串?

How to limit number of lines in a TextBox and split the lines to strings?

如何实现多行文本框的输入只能输入特定数量的行,例如仅 10 行。 此外,我想获取每一行的输入并将每一行写入一个单独的变量,以便稍后使用这些变量。如果用户收到一个消息框并警告只有 10 行是可能的,那就太好了。 任何帮助将不胜感激

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

#Assembly PresentationFramework wird geladen
Add-Type -AssemblyName PresentationFramework
$form = New-Object System.Windows.Forms.Form
$form.StartPosition = 'CenterScreen' #Formstartposition Zentrum
$form.Size = New-Object System.Drawing.Size(500,400)
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.DataBindings.DefaultDataSourceUpdateMode = 0
$textBox.Location = New-Object System.Drawing.Point((110),(90))
$textBox.Size = New-Object System.Drawing.Size(288,150)
$textBox.TabIndex = 0
$textBox.Multiline =$true

$form.Controls.Add($textBox)
$form.ShowDialog() | Out-Null

1.Get TextChanged 事件的行数。

2.Turn把iList改成了ArrayList.

3.Get最大行数与当前行数的差异。

4.Remove 来自 ArrayList 的范围。

5.SetTextbox的内容到Arraylist

6.Set 文本框末尾的光标。

$TextboxMaxLines = 10
$textBox.Add_TextChanged({
    If($textBox.Lines.Count -gt $TextboxMaxLines){
        [System.Collections.ArrayList]$AL = $textBox.Lines
        [int]$LC = ($textBox.Lines.Count - $TextboxMaxLines)
        $Al.RemoveRange($TextboxMaxLines, $LC)
        $textbox.Lines = $AL
        $textbox.SelectionStart = ($textbox.Text.Length)
        $textbox.SelectionLength = 0
    }
})