Powershell Form Question - Not sure if this is possible, but.....
okay - building form object based on text file - want shring/grow # of text boxes based on how many items in text file.
can read in great, create textbox objects on form, etc. - loop in created creating them same object name (not taking $objname$variable uniqueness.....)
going out of skull trying find way name formobjects dynamically based on text file, that's still referencable via code. reading in text file $paramarray - thats working great. nice form, looks great - when attempt grab value, grabs last created textbox....
code creating form objects (labels , boxes):
$boxcount=20
foreach ($param in $paramarray) { $paramboxtitle = $param.split(",")
$objlabel = new-object system.windows.forms.label
$objlabel.location = new-object system.drawing.size(10,$boxcount)
$objlabel.size = new-object system.drawing.size(280,20) $objlabel.text = $paramboxtitle[0] $objform.controls.add($objlabel) $objtextbox= new-object system.windows.forms.textbox $objtextbox.location = new-object system.drawing.size(10,($boxcount+20)) $objtextbox.size = new-object system.drawing.size(260,20) $objtextbox.name=$iterator $objtextbox.text=$objtextbox.name $objform.controls.add($objtextbox)
$boxcount=$boxcount+40
$iterator=$iterator+1
any ideas? want portable in event want use form other applications. please let me know - suspect lot easier making it.
}
i'm not sure understand problem. tested code , textbox names incrementally set value of $iterator (1, 2, 3) , textbox text property well. here code:
$objform = new-object system.windows.forms.form $paramarray = ("item1", "item2", "item3") $iterator = 1 $boxcount=20 $clickhandler = { [windows.forms.messagebox]::show($this.name) } foreach ($param in $paramarray) { $paramboxtitle = $param.split(",") $objlabel = new-object system.windows.forms.label $objlabel.location = new-object system.drawing.size(10,$boxcount) $objlabel.size = new-object system.drawing.size(280,20) $objlabel.text = $paramboxtitle[0] $objform.controls.add($objlabel) $objtextbox= new-object system.windows.forms.textbox $objtextbox.location = new-object system.drawing.size(10,($boxcount+20)) $objtextbox.size = new-object system.drawing.size(260,20) $objtextbox.name=$iterator $objtextbox.text=$objtextbox.name $objform.controls.add($objtextbox) $objtextbox.add_mouseclick($clickhandler) $boxcount=$boxcount+40 $iterator=$iterator+1 } $objform.showdialog()
uros calakovic
Windows Server > Windows PowerShell
Comments
Post a Comment