trying to update textbox text based on another textbox but it isn't working


ok have following script. 

$mainform = new-object system.windows.forms.form
$mainform.text = "assign $lu $newpcname"
$mainform.size = new-object system.drawing.size(600,250)
$mainform.startposition = "centerscreen"
$mainform.autoscroll = $true
$mainform.font = new-object system.drawing.font("californian fb", 14,[system.drawing.fontstyle]::bold)
$mainform.formborderstyle = "fixeddialog"
$mainform.maximizebox = $false

$npnlb = new-object system.windows.forms.label
$npnlb.size = new-object system.drawing.size(130,25)
$npnlb.location = new-object system.drawing.point(5,16)
$npnlb.text = "pc name: "

$npntb = new-object system.windows.forms.textbox
$npntb.location = new-object system.drawing.point(140,14)
$npntb.size = new-object system.drawing.size(150,35)
$npntb.text = $newpcname
$npntb.add_mouseenter({$this.backcolor = [system.drawing.color]::fromargb(6,139,138)})
$npntb.add_mouseleave({$this.backcolor = [system.drawing.color]::white})
$npntb.add_textchanged({$newpcname = $npntb.text; $mainform.refresh()})
$npntb.tabindex = 1

so have read telling me when change text in $npntb.text then $npntb.add_textchanged should fire , main form title should change reflect updated variable. not happening. there no changes form title. simplest of 2 of these trying work. figure if folks can me part other 1 should easy. have posted relevant portion of long , complicated script here.


help about_scope

also:

this line not assign variable "text" assigns current value of variable.  if change variable not change forms "text" property.  basic programming 101 , true in languages.

example:

ps c:\scripts> $x=4 ps c:\scripts> $y=$x ps c:\scripts> $y 4 ps c:\scripts> $x=99 ps c:\scripts> $y 4

help about_variables


\_(ツ)_/




Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Windows 2016 RDS event 1306 Connection Broker Client failed to redirect the user... Error: NULL