user interface - PowerShell button click event scriptblock not working -
user interface - PowerShell button click event scriptblock not working -
i working on gui several tabpage
s. there within each tabpage
several buttons should 'do' s.th.
so defined $..onclick={..}
in illustration write s.th. - doesn't work. please what's wrong?
here total illustration shows button check 1
in dialog, button isn't working @ all:
function guibutton ($window,$todo,[string]$name="butty",[string]$text="butty", [int]$x=300,[int]$y=200,[int]$w=75,[int]$h=23) { $button = new-object system.windows.forms.button $button.location = new-object system.drawing.size($x,$y) $button.size = new-object system.drawing.size($w,$h) $button.name = $name $button.text = $text $button.add_click( { $todo } ) $window.controls.add($button) } #generated form function function generateform { #region import assemblies [reflection.assembly]::loadwithpartialname("system.drawing") | out-null [reflection.assembly]::loadwithpartialname("system.windows.forms") | out-null #region generated form objects $mainmenu = new-object system.windows.forms.form $initialformwindowstate = new-object system.windows.forms.formwindowstate #buttons $testtaba = new-object system.windows.forms.button $exit = new-object system.windows.forms.button $tabcontrol = new-object system.windows.forms.tabcontrol #misc items $progressbar = new-object system.windows.forms.progressbar $statusbar = new-object system.windows.forms.statusbar #tabs $tabcontrol = new-object system.windows.forms.tabcontrol $tabtesta = new-object system.windows.forms.tabpage #---------------------------------------------- #generated event script blocks #---------------------------------------------- #provide custom code events specified in primalforms. #unknown $handler_mainmenu_load = $onloadform_statecorrection= { $mainmenu.windowstate = $initialformwindowstate } #buttons $testtaba_onclick = { $tabcontrol.selecttab($tabtesta) } $exit_onclick={ write-host "bye-bye" $mainmenu.close() } $system_drawing_size = new-object system.drawing.size $system_drawing_size.height = 474 $system_drawing_size.width = 665 $mainmenu.font = new-object system.drawing.font("mistral",8.25,0,3,0) # schriftart festlegen $mainmenu.clientsize = $system_drawing_size $mainmenu.databindings.defaultdatasourceupdatemode = 0 $mainmenu.name = "mainmenu" $mainmenu.text = "test gui" $mainmenu.topmost = $true $mainmenu.add_load($handler_form1_load) # == fix-trade button == # $testtaba.name = "testtaba" $testtaba.text = "test taba" $testtaba.tabindex = 2 $testtaba.usevisualstylebackcolor = $true $testtaba.add_click($testtaba_onclick) $testtaba.databindings.defaultdatasourceupdatemode = 0 $system_drawing_point = new-object system.drawing.point $system_drawing_point.x = 12 $system_drawing_point.y = 69 $testtaba.location = $system_drawing_point $system_drawing_size = new-object system.drawing.size $system_drawing_size.height = 35 $system_drawing_size.width = 100 $testtaba.size = $system_drawing_size $mainmenu.controls.add($testtaba) # == exit button == # $exit.name = "exit" $exit.text = "exit" $exit.tabindex = 7 $exit.usevisualstylebackcolor = $true $exit.add_click($exit_onclick) $exit.databindings.defaultdatasourceupdatemode = 0 $system_drawing_point = new-object system.drawing.point $system_drawing_point.x = 12 $system_drawing_point.y = 274 $exit.location = $system_drawing_point $system_drawing_size = new-object system.drawing.size $system_drawing_size.height = 35 $system_drawing_size.width = 100 $exit.size = $system_drawing_size $mainmenu.controls.add($exit) # == tab command == # $tabcontrol.name = "tabcontrol" $tabcontrol.tabindex = 4 $tabcontrol.selectedindex = 0 $tabcontrol.databindings.defaultdatasourceupdatemode = 0 $system_drawing_point = new-object system.drawing.point $system_drawing_point.x = 118 $system_drawing_point.y = 70 $tabcontrol.location = $system_drawing_point $system_drawing_size = new-object system.drawing.size $system_drawing_size.height = 374 $system_drawing_size.width = 535 $tabcontrol.size = $system_drawing_size # add together next tabcontrol property-setting section: $tabsizemode = new-object system.windows.forms.tabsizemode $tabsizemode = "fixed" $tabcontrol.sizemode =$tabsizemode $tabcontrol.itemsize = new-object system.drawing.size(0, 1) $tabappearance = new-object system.windows.forms.tabappearance $tabappearance = "buttons" $tabcontrol.appearance = $tabappearance $mainmenu.controls.add($tabcontrol) $check1button_onclick = { write-host "check1-click, mach was.. " } # == trade tab == # $tabtesta.databindings.defaultdatasourceupdatemode = 0 $tabtesta.name = "testtaba" $system_drawing_point = new-object system.drawing.point $system_drawing_point.x = 4 $system_drawing_point.y = 22 $tabtesta.location = $system_drawing_point $system_drawing_size = new-object system.drawing.size $system_drawing_size.height = 205 $system_drawing_size.width = 445 $tabtesta.size = $system_drawing_size $tabtesta.tabindex = 2 $tabtesta.text = "tab2" $tabtesta.usevisualstylebackcolor = $true # name txt x y w h guibutton $tabtesta $check1button_onclick "check1" "check 1" 10 20 75 23 $tabcontrol.controls.add($tabtesta) # == progress bar == # $progressbar.databindings.defaultdatasourceupdatemode = 0 $system_drawing_point = new-object system.drawing.point $system_drawing_point.x = 589 $system_drawing_point.y = 458 $progressbar.location = $system_drawing_point $progressbar.name = "progressbar" $system_drawing_size = new-object system.drawing.size $system_drawing_size.height = 15 $system_drawing_size.width = 75 $progressbar.size = $system_drawing_size $progressbar.tabindex = 0 $mainmenu.controls.add($progressbar) # == status bar == # $statusbar.databindings.defaultdatasourceupdatemode = 0 $system_drawing_point = new-object system.drawing.point $system_drawing_point.x = 0 $system_drawing_point.y = 456 $statusbar.location = $system_drawing_point $statusbar.name = "statusbar" $system_drawing_size = new-object system.drawing.size $system_drawing_size.height = 18 $system_drawing_size.width = 665 $statusbar.size = $system_drawing_size $statusbar.tabindex = 1 $statusbar.text = "statusbar - text..." $statusbar.add_panelclick($statusbar_panelclick) $mainmenu.controls.add($statusbar) #to show tabs switching correctly, add: $tabtesta.backcolor = "white" # == save , open form == # $initialformwindowstate = $mainmenu.windowstate $mainmenu.add_load($onloadform_statecorrection) $mainmenu.showdialog()| out-null } #end function #call function generateform
if start gui dialog appears, if click on button should write-host ".."
nil happens :(
you wrapping passed in scriptblock in scriptblock. alter line:
$button.add_click({$todo})
to
$button.add_click($todo)
you might want specify type of $todo
scriptblock.
function guibutton($window,[scriptblock]$todo,[string]$name="butty",[string]$text="butty", ...
in future, should seek problem script downwards minimum possible script duplicates problem. happened spot problem @ top of script.
powershell user-interface
Comments
Post a Comment