winforms - One button with 2 actions -
i did try make 1 button makes 2 actions: 1 on 1st press (click), other on 2nd press (click), , repeat. however, none of approaches worked me, made 2nd button make 2nd action, have one. here small example should me :).
#this creates button , sets event $okbutton = new-object system.windows.forms.button $okbutton.location = new-object system.drawing.size(60,20) $okbutton.size = new-object system.drawing.size(30,20) $okbutton.text = "all" $okbutton.add_click({ $ua2checkbox.checked=$true; $nvscheckbox.checked=$true; $krscheckbox.checked=$true; $uacheckbox.checked=$true; $hbrcheckbox.checked=$true; }) $objform.controls.add($okbutton) $objform.add_shown({$objform.activate()}) #this creates none button , sets event $okbutton = new-object system.windows.forms.button $okbutton.location = new-object system.drawing.size(100,20) $okbutton.size = new-object system.drawing.size(40,20) $okbutton.text = "none" $okbutton.add_click({ $ua2checkbox.checked=$false; $nvscheckbox.checked=$false; $krscheckbox.checked=$false; $uacheckbox.checked=$false; $hbrcheckbox.checked=$false; }) $objform.controls.add($okbutton) $objform.add_shown({$objform.activate()})
$actionall = { #$ua2checkbox.checked=$true;$nvscheckbox.checked=$true;$krscheckbox.checked=$true;$uacheckbox.checked=$true;$hbrcheckbox.checked=$true; #$okbutton.add_click($ua2checkbox.checked=$true;$nvscheckbox.checked=$true;$krscheckbox.checked=$true;$uacheckbox.checked=$true;$hbrcheckbox.checked=$true;) #$okbutton.remove_click({$ua2checkbox.checked=$false;$nvscheckbox.checked=$false;$krscheckbox.checked=$false;$uacheckbox.checked=$false;$hbrcheckbox.checked=$false;}) } $actionnone = { #$ua2checkbox.checked=$false;$nvscheckbox.checked=$false;$krscheckbox.checked=$false;$uacheckbox.checked=$false;$hbrcheckbox.checked=$false; #$okbutton.add_click($ua2checkbox.checked=$false;$nvscheckbox.checked=$false;$krscheckbox.checked=$false;$uacheckbox.checked=$false;$hbrcheckbox.checked=$false;) #$okbutton.remove_click({$ua2checkbox.checked=$false;$nvscheckbox.checked=$false;$krscheckbox.checked=$false;$uacheckbox.checked=$false;$hbrcheckbox.checked=$false;}) } $okbutton.location = new-object system.drawing.size(60,20) $okbutton.size = new-object system.drawing.size(30,20) $okbutton.text = "all" $okbutton.add_click({invoke-expression "$actionall"}) $okbutton.remove_click({invoke-expression "$actionnone"}) #$okbutton.mousedoubleclick({$ua2checkbox.checked=$false;$nvscheckbox.checked=$false;$krscheckbox.checked=$false;$uacheckbox.checked=$false;$hbrcheckbox.checked=$false;}) $objform.controls.add($okbutton) $objform.add_shown({$objform.activate()})
if want toggle action of button each time button clicked, need replace current action other action within each action:
$actionall = { # other operations here $okbutton.text = 'none' $okbutton.remove_click($actionall) $okbutton.add_click($actionnone) } $actionnone = { # other operations here $okbutton.text = 'all' $okbutton.remove_click($actionnone) $okbutton.add_click($actionall) } $okbutton = new-object system.windows.forms.button $okbutton.text = 'all' $okbutton.add_click($actionall) $objform.controls.add($okbutton)
Comments
Post a Comment