我需要使用PowerShell构建GUI的原型。
单击时,OnClick $Bcancel.add_click({$form.Close})
事件无法启动。
这是我的脚本的缩短版本。
# Version: 2.0 #
# Stand: 12. September 2017 #
#############################
Import-Module ActiveDirectory
# Deklarierung
$ActiveApp = "FIS"
$ComboBoxApp = @("eGov","FIS","VI","DV","Axioma","Liegenschaften","HR Portal","Tutoris")
$ComboBoxUrgency = @("Geringe Dringlichkeit","Mittlere Dringlichkeit","Höchste Dringlichkeit")
$ComboBoxPrioT = @("Geringe Prorität","Mittlere Priorität","Höchste Priorität")
$ComboBoxCategory = @("Systemausfall","Unerklärliches Systemverhalten")
$ActiveUser
$CoordinatorGroup = "BFO Management"
# Declaration for POB
$CaseType
$Description
$CDAChangetyp
$Urgency
$CaseCategory
$ContactOrganisation
$ContactCustomer
$ContactNotifyby
$IsOkForWeb
$Coordinator
$Responsible
$Reference
$memo
$XMLBuffer = "*********** XML Buffer ***********"
#Recognizes the active user
$ActiveUserNP = Get-WMIObject -class Win32_ComputerSystem | select username
$ActiveUser1 = $ActiveUserNP.username
############################################# Fenster #############################################
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$Form = New-Object system.Windows.Forms.Form
$Form.Text = "VRSG | Support Ticket - $ActiveApp"
$Form.TopMost = $true
$Form.Width = 600
$Form.Height = 570
############################################# Linke Reihe #############################################
$labelTitel = New-Object system.windows.Forms.Label
$labelTitel.Text = "VRSG |"
$LabelTitel.ForeColor = "#009454"
$labelTitel.AutoSize = $true
$labelTitel.Width = 25
$labelTitel.Height = 10
$labelTitel.location = new-object system.drawing.point(20,20)
$labelTitel.Font = "Arial Narrow,16,style=Bold"
$Form.controls.Add($labelTitel)
$labelTitel2 = New-Object system.windows.Forms.Label
$labelTitel2.Text = "Support"
$labelTitel2.AutoSize = $true
$labelTitel2.Width = 25
$labelTitel2.Height = 10
$labelTitel2.location = new-object system.drawing.point(85,20)
$labelTitel2.Font = "Arial Narrow,16,style=Bold"
$Form.controls.Add($labelTitel2)
$label2 = New-Object system.windows.Forms.Label
$label2.Text = "Application Incident"
$label2.AutoSize = $true
$label2.Width = 25
$label2.Height = 10
$label2.location = new-object system.drawing.point(20,80)
$label2.Font = "Arial Narrow,14,style=Bold"
$Form.controls.Add($label2)
$LabelAllg = New-Object system.windows.Forms.Label
$LabelAllg.Text = "General Information"
$LabelAllg.AutoSize = $true
$LabelAllg.Width = 25
$LabelAllg.Height = 10
$LabelAllg.location = new-object system.drawing.point(20,120)
$LabelAllg.Font = "Arial Narrow,12,style=Bold"
$Form.controls.Add($LabelAllg)
$LabelBet = New-Object system.windows.Forms.Label
$LabelBet.Text = "Title *"
$LabelBet.AutoSize = $true
$LabelBet.Width = 25
$LabelBet.Height = 10
$LabelBet.location = new-object system.drawing.point(20,155)
$LabelBet.Font = "Arial Narrow,10,style=Bold"
$Form.controls.Add($LabelBet)
$tbBetreff = New-Object system.windows.Forms.TextBox
$tbBetreff.Width = 250
$tbBetreff.Height = 20
$tbBetreff.location = new-object system.drawing.point(20,175)
$tbBetreff.Font = "Microsoft Sans Serif,10"
$Form.controls.Add($tbBetreff)
$LabelCat = New-Object system.windows.Forms.Label
$LabelCat.Text = "Description*"
$LabelCat.AutoSize = $true
$LabelCat.Width = 25
$LabelCat.Height = 10
$LabelCat.location = new-object system.drawing.point(20,315)
$LabelCat.Font = "Arial Narrow,12,style=Bold"
$Form.controls.Add($LabelCat)
$LabelCat = New-Object system.windows.Forms.Label
$LabelCat.Text = "Please describe your Problem"
$LabelCat.AutoSize = $true
$LabelCat.Width = 25
$LabelCat.Height = 10
$LabelCat.location = new-object system.drawing.point(20,335)
$LabelCat.Font = "Arial Narrow,11"
$Form.controls.Add($LabelCat)
$textbox4 = New-Object system.windows.Forms.TextBox
$textbox4.Width = 540
$textbox4.Height = 100
$textbox4.location = new-object system.drawing.point(20,360)
$textbox4.MultiLine = $True
$textbox4.Font = "Arial Narrow,10"
$Form.controls.Add($textbox4)
############################################# Right side #############################################
$LabelAdm = New-Object system.windows.Forms.Label
$LabelAdm.Text = "administrative information"
$LabelAdm.AutoSize = $true
$LabelAdm.Width = 25
$LabelAdm.Height = 10
$LabelAdm.location = new-object system.drawing.point(350,120)
$LabelAdm.Font = "Arial Narrow,12,style=Bold"
$Form.controls.Add($LabelAdm)
$LabelUser = New-Object system.windows.Forms.Label
$LabelUser.Text = "Ticket opened by"
$LabelUser.AutoSize = $true
$LabelUser.Width = 25
$LabelUser.Height = 10
$LabelUser.location = new-object system.drawing.point(350,155)
$LabelUser.Font = "Arial Narrow,10,style=Bold"
$Form.controls.Add($LabelUser)
$LabelUser = New-Object system.windows.Forms.Label
$LabelUser.Text = "$ActiveUser1"
$LabelUser.AutoSize = $true
$LabelUser.Width = 25
$LabelUser.Height = 10
$LabelUser.location = new-object system.drawing.point(350,175)
$LabelUser.Font = "Arial Narrow,10"
$Form.controls.Add($LabelUser)
$LabelUser = New-Object system.windows.Forms.Label
$LabelUser.Text = "Affected application"
$LabelUser.AutoSize = $true
$LabelUser.Width = 25
$LabelUser.Height = 10
$LabelUser.location = new-object system.drawing.point(350,205)
$LabelUser.Font = "Arial Narrow,10,style=Bold"
$Form.controls.Add($LabelUser)
$LabelUser = New-Object system.windows.Forms.Label
$LabelUser.Text = "FIS (Finance Suite)"
$LabelUser.AutoSize = $true
$LabelUser.Width = 25
$LabelUser.Height = 10
$LabelUser.location = new-object system.drawing.point(350,225)
$LabelUser.Font = "Arial Narrow,10"
$Form.controls.Add($LabelUser)
$LabeApp = New-Object system.windows.Forms.Label
$LabeApp.Text = "Coordinator-Group"
$LabeApp.AutoSize = $true
$LabeApp.Width = 25
$LabeApp.Height = 10
$LabeApp.location = new-object system.drawing.point(350,255)
$LabeApp.Font = "Arial Narrow,10,style=Bold"
$Form.controls.Add($LabeApp)
$LabelUser = New-Object system.windows.Forms.Label
$LabelUser.Text = "$CoordinatorGroup"
$LabelUser.AutoSize = $true
$LabelUser.Width = 25
$LabelUser.Height = 10
$LabelUser.location = new-object system.drawing.point(350,275)
$LabelUser.Font = "Arial Narrow,10"
$Form.controls.Add($LabelUser)
############################################# Buttons #############################################
$Bcancel = New-Object system.windows.Forms.Button
$Bcancel.Text = "Cancel"
$Bcancel.Width = 90
$Bcancel.Height = 30
$Bcancel.location = new-object system.drawing.point(370,490)
$Bcancel.Font = "Arial Narrow,12,style=Bold"
$Form.controls.Add($Bcancel)
$Bsend = New-Object system.windows.Forms.Button
$Bsend.Text = "Send"
$Bsend.Width = 90
$Bsend.Height = 30
$Bsend.location = new-object system.drawing.point(470,490)
$Bsend.Font = "Arial Narrow,12,style=Bold"
$Form.controls.Add($Bsend)
############################################# Button Events #############################################
#Add Button event
$Bcancel.add_click({$form.Close})
[void]$Form.ShowDialog()
$Form.Dispose()
我已经看到一些在堆栈溢出方面存在类似问题的人,但他们的解决方案并不适用于我。
有人知道这里出了什么问题吗?
谢谢!