我有一个Powershell GUI,它可以导入文本文件,并在单击按钮时将其显示在文本框中。
但是,即使文本文件在文本框中显示时每行包含一个条目,也全部位于一行上...
文本文件看起来像这样-
但是当我导入它时,它看起来像这样-
这是我正在使用的代码-
$button_hosts = New-Object system.windows.Forms.Button
$button_hosts.Text = "Hosts"
$button_hosts.Width = 60
$button_hosts.Height = 25
$button_hosts.location = new-object system.drawing.point(20,55)
$button_hosts.Font = "Microsoft Sans Serif,10"
$mydocs = [Environment]::GetFolderPath('MyDocuments')
$button_hosts.Add_Click({
$textBox_hosts.Text = Get-Filename "$mydocs" txt
$textBox_hostlist.Text = Get-Content $textBox_hosts.Text
})
$GUI.controls.Add($button_hosts)
知道如何使其显示相同吗?我无法将任何额外的数据添加到txt文件中,因为它是另一个程序的输出
最佳答案
设置lines属性,而不是text属性。
$textBox_hostlist.Lines = Get-Content $textBox_hosts.Text
关于powershell - Powershell GUI导入的文本文件缺少换行符/回车符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44725813/