Powershell Form Button onclick event doesn't work as expected -
i need build prototype of gui powershell. onclick $bcancel.add_click({$form.close}) event doesn't start when clicked.
here shortened version of script.
# 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 pob $casetype $description $cdachangetyp $urgency $casecategory $contactorganisation $contactcustomer $contactnotifyby $isokforweb $coordinator $responsible $reference $memo $xmlbuffer = "*********** xml buffer ***********" #recognizes 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 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() i've seen guys similar problems on stack overflow, solutions didn't work me.
does know went wrong here?
thank you!
Comments
Post a Comment