[英]Create Powershell GUI with Visual Studio
I am using Visual Studio to create a GUI environment for all my PowerShell scripts together to create a common platform . 我正在使用Visual Studio为我所有的PowerShell脚本创建GUI环境,以创建一个通用平台。 I have one problem with the text box .
我的文本框有一个问题。 I want to have a text box so all the results appear there .
我想要一个文本框,以便所有结果都出现在这里。 Right now only the last command is appearing there .
现在只有最后一个命令出现在这里。
Any suggestions ? 有什么建议么 ?
<TextBox x:Name="Information" HorizontalAlignment="Left" Margin="10,116,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Grid.ColumnSpan="3" Height="255" Width="678"/>
and I want at this texbox to appear the following messages 我希望在此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"
})
By setting the text in $WPFInformation.Text
for the second drive mapping ( V:
), you overwrite the text you have set in there earlier for the N:
mapping. 通过在
$WPFInformation.Text
为第二个驱动器映射( V:
$WPFInformation.Text
设置文本,您将覆盖先前在其中为N:
映射设置的文本。
To append extra lines to the textbox, use 要将额外的行添加到文本框,请使用
$WPFInformation.Text += [Environment]::NewLine
$WPFInformation.Text += " V drive is already mounted and accessible"
etc. for every next line you want to add. 等您要添加的下一行。
You can also use AppendText()
to add the new lines in there: 您还可以使用
AppendText()
在其中添加新行:
$WPFInformation.AppendText("`r`n V drive is already mounted and accessible")
Where `r`n represents the CRLF
newline. 其中`r`n代表
CRLF
换行符。
ps Of course, make sure the textbox's MultiLine property is set to $WPFInformation.Multiline = $true
ps当然,请确保文本框的MultiLine属性设置为
$WPFInformation.Multiline = $true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.