繁体   English   中英

使用Visual Studio创建Powershell GUI

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM