【问题标题】:Create Powershell GUI with Visual Studio使用 Visual Studio 创建 Powershell GUI
【发布时间】:2018-12-24 21:43:15
【问题描述】:

我正在使用 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"
})

【问题讨论】:

  • 有什么代码可以分享吗?
  • 没有显示代码的相关部分,我怀疑是否有人能够回答这个问题..
  • 我会尝试分享一部分代码但不知道是否有帮助

标签: visual-studio powershell


【解决方案1】:

通过为第二个驱动器映射 (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 换行符。

附言当然,请确保文本框的 MultiLine 属性设置为$WPFInformation.Multiline = $true

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-29
    • 1970-01-01
    • 2018-06-05
    • 1970-01-01
    相关资源
    最近更新 更多