2

有谁知道为什么 .net 表单会在 Powershell ISE 中显示默认的 3D 外观,但在运行 .ps1 时不会显示?我已将按钮的平面样式更改为“标准”,没有任何变化。我安装了 .net 4.5。“弹出式”平面样式确实改变了外观,但这不是我想要的。日历和工具提示看起来也完全不同。我尝试添加这一行,但没有任何区别:

$MenuBox.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::Fixed3D

屏幕截图和代码示例如下。谢谢。

截屏

    # Create a listbox to select the region
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

    # Menu Layout
    $MenuBox = New-Object System.Windows.Forms.Form
    $MenuBox.Size = New-Object System.Drawing.Size @(650,450)
    $MenuBox.Text = "Auto v" + $VersionNumber + " - Powershell"
    $MenuBox.StartPosition = "CenterScreen"
    $MenuBox.AutoSize = $False
    $MenuBox.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::Fixed3D

    # Menu Header Text
    $MenuHeader = New-Object System.Windows.Forms.Label
    $MenuHeader.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",14,1,3,1)
    $MenuHeader.Location = New-Object System.Drawing.Size(118,20)
    $MenuHeader.Size = New-Object System.Drawing.Size(380,40) 
    $MenuHeader.Text = "$MenuHeaderText"
    $MenuHeader.TextAlign = [System.Drawing.ContentAlignment]::TopCenter
    $MenuBox.Controls.Add($MenuHeader)

    # Add Region List Box
    If ($RegionListBoxAvailable -eq "True") {
        $RegionListBoxLabel = New-Object System.Windows.Forms.Label
        $RegionListBoxLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",10,0,3,1)
        $RegionListBoxLabel.Location = New-Object System.Drawing.Size(60,80) 
        $RegionListBoxLabel.Size = New-Object System.Drawing.Size(280,20) 
        $RegionListBoxLabel.Text = "Select the REGION:"
        $MenuBox.Controls.Add($RegionListBoxLabel)

        $RegionListBox = New-Object System.Windows.Forms.ListBox 
        $RegionListBox.Location = New-Object System.Drawing.Size(62,100) 
        $RegionListBox.Size = New-Object System.Drawing.Size(130,42) 
        $RegionListBox.Height = 42
        [void] $RegionListBox.Items.Add("Alabama HQ Devices")
        [void] $RegionListBox.Items.Add("Carolinas HQ Devices")
        $RegionListBox.SetSelected(0,$True)
        $global:RegionSelect = $RegionListBox.SelectedItems
        $MenuBox.Controls.Add($RegionListBox)

        $RegionListBoxToolTip = New-Object System.Windows.Forms.ToolTip
        $RegionListBoxToolTip.IsBalloon = $True
        $RegionListBoxToolTip.InitialDelay = 1000
        $RegionListBoxToolTip.SetToolTip($RegionListBox, "Select a region based on HQ")
        }

    # Add Labels for Menu Elements
    If (!($BoxLabelText -eq $Null)) {
        $BoxLabel = New-Object System.Windows.Forms.Label
        $BoxLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",10,0,3,1)
        $BoxLabel.Location = New-Object System.Drawing.Size(10,60) 
        $BoxLabel.Size = New-Object System.Drawing.Size(680,20) 
        $BoxLabel.Text = "$BoxLabelText"
        $MenuBox.Controls.Add($BoxLabel)
        }

    # Button 7
    If (!($ButtonList[6] -eq "Nothing")) {
        $Button7 = New-Object System.Windows.Forms.Button
        $Button7.Location = New-Object System.Drawing.Size(62,60)
        $Button7.Size = New-Object System.Drawing.Size(500,30)
        $Button7.Add_Click({
            $global:ButtonResult = $ButtonList[6]
            $MenuBox.Close()
            })
        $Button7.Text = $ButtonList[6]
        $Button7.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",12,0,3,1)
        $MenuBox.Controls.Add($Button7)
        }

    # Button 6
    If (!($ButtonList[5] -eq "Nothing")) {
        $Button6 = New-Object System.Windows.Forms.Button
        $Button6.Location = New-Object System.Drawing.Size(62,100)
        $Button6.Size = New-Object System.Drawing.Size(500,30)
        $Button6.Add_Click({
            $global:ButtonResult = $ButtonList[5]
            $MenuBox.Close()
            })
        $Button6.Text = $ButtonList[5]
        $Button6.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",12,0,3,1)
        $MenuBox.Controls.Add($Button6)
        }

    # Button 5
    If (!($ButtonList[4] -eq "Nothing")) {
        $Button5 = New-Object System.Windows.Forms.Button
        $Button5.Location = New-Object System.Drawing.Size(62,140)
        $Button5.Size = New-Object System.Drawing.Size(500,30)
        $Button5.Add_Click({
            $global:ButtonResult = $ButtonList[4]
            $MenuBox.Close()
            })
        $Button5.Text = $ButtonList[4]
        $Button5.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",12,0,3,1)
        $MenuBox.Controls.Add($Button5)
        }

    # Button 4
    If (!($ButtonList[3] -eq "Nothing")) {
        $Button4 = New-Object System.Windows.Forms.Button
        $Button4.Location = New-Object System.Drawing.Size(62,180)
        $Button4.Size = New-Object System.Drawing.Size(500,30)
        $Button4.Add_Click({
            $global:ButtonResult = $ButtonList[3]
            $MenuBox.Close()
            })
        $Button4.Text = $ButtonList[3]
        $Button4.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",12,0,3,1)
        $MenuBox.Controls.Add($Button4)
        }

    # Button 3
    If (!($ButtonList[2] -eq "Nothing")) {
        $Button3 = New-Object System.Windows.Forms.Button
        $Button3.Location = New-Object System.Drawing.Size(62,220)
        $Button3.Size = New-Object System.Drawing.Size(500,30)
        $Button3.Add_Click({
            $global:ButtonResult = $ButtonList[2]
            $MenuBox.Close()
            })
        $Button3.Text = $ButtonList[2]
        $Button3.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",12,0,3,1)
        $MenuBox.Controls.Add($Button3)
        }

    # Button 2
    If (!($ButtonList[1] -eq "Nothing")) {
        $Button2 = New-Object System.Windows.Forms.Button
        $Button2.Location = New-Object System.Drawing.Size(62,260)
        $Button2.Size = New-Object System.Drawing.Size(500,30)
        $Button2.Add_Click({
            $global:ButtonResult = $ButtonList[1]
            $MenuBox.Close()
            })
        $Button2.Text = $ButtonList[1]
        $Button2.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",12,0,3,1)
        $MenuBox.Controls.Add($Button2)
        }

    # Button 1 - Includes $Search Variable
    If (!($ButtonList[0] -eq "Nothing")) {
        $Button1 = New-Object System.Windows.Forms.Button
        $Button1.Location = New-Object System.Drawing.Size(62,300)
        $Button1.Size = New-Object System.Drawing.Size(500,30)
        $Button1.Add_Click({
            $global:ButtonResult = $ButtonList[0]
            $MenuBox.Close()
            })
        $Button1.Text = $ButtonList[0]
        #$Button1.Text.MouseOverColor = [System.Drawing.Color]::White
        #$Button1.TextAlign = [System.Drawing.ContentAlignment]::TopCenter
        $Button1.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",12,0,3,1)
        $MenuBox.Controls.Add($Button1)
        }

    # Calendar
    If ($CalendarAvailable -eq $True) {
        $Calendar = New-Object System.Windows.Forms.MonthCalendar 
        $Calendar.Location = New-Object System.Drawing.Size(12,80)
        $Calendar.ShowTodayCircle = $False
        $Calendar.MaxDate = Get-Date
        $Calendar.MinDate = $OldestLog
        $Calendar.MaxSelectionCount = "$CalendarDateRange"
        $MenuBox.Controls.Add($Calendar) 
        }

    # Exit Button
    $ExitButton = New-Object System.Windows.Forms.Button
    $ExitButton.Location = New-Object System.Drawing.Size(540,370)
    $ExitButton.Size = New-Object System.Drawing.Size(75,23)
    $ExitButton.Text = "Exit"
    $ExitButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",11,0,3,1)
    $ExitButton.Add_Click({
        Remove-Item "$WorkingDirectory\Temp\*.*" -Force
        $MenuBox.Close()
        })
    $MenuBox.Controls.Add($ExitButton)

    # Show Menu
    $MenuBox.Topmost = $True
    $MenuBox.Add_Shown({$MenuBox.Activate()})
    [void] $MenuBox.ShowDialog()
4

1 回答 1

3

尝试将其包含在您的表单创建代码中:

[System.Windows.Forms.Application]::EnableVisualStyles()

它使您的表单具有“现代”视觉风格。

于 2013-03-12T18:27:16.590 回答