powershell - Powershell GUI导入的文本文件缺少换行符/回车符

标签 powershell user-interface textbox

我有一个Powershell GUI,它可以导入文本文件,并在单击按钮时将其显示在文本框中。

但是,即使文本文件在文本框中显示时每行包含一个条目,也全部位于一行上...

文本文件看起来像这样-

TXT

但是当我导入它时,它看起来像这样-

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/

相关文章:

powershell - 从 Powershell 启动 vNext 构建并获取工件

powershell - 无法获取参数集进行验证

android - 像这样滚动标签?

user-interface - 如何将所有绘图菜单(文件、编辑、插入等)集成到 matlab GUI 中?

WPF:文本框不触发 onTextInput 事件

unix - 相当于 PowerShell 中的 *Nix 'which' 命令?

windows - 使用 powershell 设置 Windows 屏幕保护程序需要密码

iphone - 背景图像/导航栏图像 iOS 的正确尺寸

c# - 尝试在 asp.net 中启用显示/隐藏功能

c# - 如何禁用文本框上的选择