Powershell 创建具有不同颜色的多条线的最佳方法
我试图找出,什么是最好的方式,以输出不同颜色的多行。 我有几个选择,但每一个都在某种程度上具有挑战性。我认为我的可能性是:Powershell 创建具有不同颜色的多条线的最佳方法,powershell,fonts,textbox,label,multiline,Powershell,Fonts,Textbox,Label,Multiline,我试图找出,什么是最好的方式,以输出不同颜色的多行。 我有几个选择,但每一个都在某种程度上具有挑战性。我认为我的可能性是: 列表框 文本框 标签 我正在建立一个词汇训练器,在测试过程中,你必须写单词。在测试结束时,我想总结一下测试 第一个挑战是,测试的长度不同,这意味着它只能测试10个单词或更多。目标是,向每个问题展示答案,并分析答案是否正确和错误,如果错误,错误在哪里。这部分我已经解决了 但现在的问题是,如何呈现结果 Listbox和Textbox当然更容易处理,但如果我理解正确的话,输出
- 列表框
- 文本框
- 标签
Clear-Host
$Frage = 'Hello World'
$Antwort = 'Hello Warld'
$Script:Counter = 0
$wordlength = $Frage.Length
Do {
if ($Antwort[$Script:Counter] -ne $Frage[$Script:Counter]) { break }
Write-Host $Frage[$Script:Counter] -NoNewline;
Write-Host -ForegroundColor Red ' '$Antwort[$Script:Counter]
$Script:Counter++
} # End of 'Do'
Until ($Script:Counter -eq $wordlength)
If ($Antwort.Length -gt $Frage.Length) {
$TooShortDifference = $Antwort[($Frage.Length)..($Antwort.Length)]
Write-Host ''
Write-Host -ForegroundColor Red 'Your Answer has too many letters'
Write-Host ''
Write-Host -ForegroundColor Green -NoNewline 'You wrote: '
Write-Host $Firstpart -NoNewline;
Write-Host $TooShortDifference -ForegroundColor Red
Write-Host ''
Write-Host -ForegroundColor Green -NoNewline 'The answer is: '
Write-Host -ForegroundColor White $Frage
Write-Host ''
}
Elseif ($Antwort.Length -lt $Frage.Length) {
$TooLongDifference = $Frage[($Antwort.Length)..$Frage.Length]
Write-Host ''
Write-Host -ForegroundColor Red 'Your Answer has not enough letters'
Write-Host ''
Write-Host -ForegroundColor Green -NoNewline 'You wrote: '
Write-Host -ForegroundColor White $Antwort
Write-Host ''
Write-Host -ForegroundColor Green -NoNewline 'The answer is: '
Write-Host -ForegroundColor White $Antwort -NoNewline
Write-Host -ForegroundColor Red $TooLongDifference -Separator ''
}
Elseif ($Antwort.Length -eq $Frage.Length) {
$SameLengthWithError = $Frage[0..($Script:Counter - 1)]
Write-Host ''
Write-Host -ForegroundColor Red 'Your Answer has a letter mismatch'
Write-Host ''
Write-Host -ForegroundColor White 'You Wrote: ' -NoNewline
Write-Host $SameLengthWithError -NoNewline -Separator ''
Write-Host $Antwort[$Script:Counter] -ForegroundColor Red -NoNewline
Write-Host $Antwort[($Script:Counter + 1)..$Antwort.Length] -Separator ''
Write-Host ''
Write-Host -ForegroundColor Green 'The Answer is: ' -NoNewline
Write-Host -ForegroundColor Green $Frage
}
Else {
Write-Host -ForegroundColor Green 'Everything was correct'
}
如果要构建类似的内容,您会使用哪种方式以及如何显示多行,字体中每行的颜色会在哪里发生变化?请查看。我想你应该用RichTextboxHello Theo,这样行得通。我需要研究和理解这一点,但它看起来很有希望,比现在好多了