gpt4 book ai didi

Powershell 多行文本框输出

转载 作者:行者123 更新时间:2023-12-05 04:04:48 27 4
gpt4 key购买 nike

使用下面的 powershell 代码,我试图输出单独的行,但由于某种原因只显示最后一行。有什么方法可以在文本框中显示多行?

$objTextBox3 = New-Object System.Windows.Forms.TextBox 
$objTextBox3.Multiline = $True;
$objTextBox3.Location = New-Object System.Drawing.Size(10,160)
$objTextBox3.Size = New-Object System.Drawing.Size(260,100)
$objTextBox3.Scrollbars = "Vertical"
$objForm.Controls.Add($objTextBox3)

$objTextBox3.Text = "TEST-" + $objTextBox2.Text + " FirstLine" + " (P) r`n TEST-" + $objTextBox2.Text + "SecondLine" + " (P)"

认为使用 r`n 可行吗?

TIA

最佳答案

Mike Shepard在对问题的评论中提供了关键指针:

您的字符串在 r 之前缺少 ` 以使 `r`n` 扩展为 CRLF newline - 也就是说,Windows 风格的换行符CR character 组成("`r") 紧跟一个 LF character (“`n”)。

因此:

$objTextBox3.Text = "TEST-" + $objTextBox2.Text + " FirstLine" + " (P) `r`n  TEST-" + 
$objTextBox2.Text + "SecondLine" + " (P)"

请注意 `r`n 周围的空格被保留。

不同于 PowerShell 本身 - 通常接受 CRLF、LF 和 CR 换行可互换 - WinForms.Multiline 设置为$True[System.Windows.Forms.TextBox] 控件 将CRLF 序列识别为显示方面的换行符。

在 GUI 中显示字符串时,一个 LF(-only) 换行符 - 你的字符串被错误地使用了,但实际上被使用了 - 被悄悄地忽略(尽管它被保留在控件的 .Text 属性中)。

关于Powershell 多行文本框输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52046370/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com