[英]Create Powershell GUI with Visual Studio
我正在使用Visual Studio為我所有的PowerShell腳本創建GUI環境,以創建一個通用平台。 我的文本框有一個問題。 我想要一個文本框,以便所有結果都出現在這里。 現在只有最后一個命令出現在這里。
有什么建議么 ?
<TextBox x:Name="Information" HorizontalAlignment="Left" Margin="10,116,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Grid.ColumnSpan="3" Height="255" Width="678"/>
我希望在此texbox出現以下消息
$WPFMapping.Add_Click({
{
$WPFInformation.Text = " We Will try to map the drives"}
if (((New-Object System.IO.DriveInfo("N:")).DriveType -ne
"NoRootDirectory"))
{
$WPFInformation.Text = " N drive is already mounted and accessible"}
else {
net use /persistent:yes N: "this drive"
Write-Host "mounting"}
if (((New-Object System.IO.DriveInfo("V:")).DriveType -ne
"NoRootDirectory"))
{
$WPFInformation.Text = " V drive is already mounted and accessible"}
else {
$WPFInformation.Text = " V drive mapping in progress"}
net use /persistent:yes V: "this drive"
$WPFInformation.Text = " V drive mapping has been completed"
})
通過在$WPFInformation.Text
為第二個驅動器映射( V:
$WPFInformation.Text
設置文本,您將覆蓋先前在其中為N:
映射設置的文本。
要將額外的行添加到文本框,請使用
$WPFInformation.Text += [Environment]::NewLine
$WPFInformation.Text += " V drive is already mounted and accessible"
等您要添加的下一行。
您還可以使用AppendText()
在其中添加新行:
$WPFInformation.AppendText("`r`n V drive is already mounted and accessible")
其中`r`n代表CRLF
換行符。
ps當然,請確保文本框的MultiLine屬性設置為$WPFInformation.Multiline = $true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.