I Build a Gui Script USing ISE
But i am trying to assign the user input in text box to a variable but it doesn’t work
This is Part of my Code
[reflection.assembly]::LoadWithPartialName("system.windows.forms")
#Creat main Form
$Main_Form = New-Object System.Windows.Forms.Form
$Main_Form.width = 500
$Main_Form.Height = 500
$Main_Form.text = " USB Delegator "
$ICON = New-Object System.Drawing.Icon ("C:\Users\Karem\Desktop\BAD\Kariem.ico")
$Main_Form.icon = $ICON
$Main_Form.Controls.Add($User_Box)
$Main_Form.Controls.Add($User_Label)
$Main_Form.Controls.Add($Pass_Box)
$Main_Form.Controls.Add($Pass_Label)
$Main_Form.Controls.Add($Login)
#Creat Uer Name Text Box
$User_Box = New-Object System.Windows.Forms.TextBox
$User_Box.width = 350
$User_Box.Height = 75
$User_Box.top = 200
$User_Box.left = 100
#Creat Login Button
$Login = New-Object System.Windows.Forms.Button
$Login.text = "Login"
$Login.Autosize = $true
$Login.top = 300
$Login.left = 200
$font_login = New-Object System.Drawing.Font ( "Sans Serif " , 9 , [System.Drawing.FontStyle]::Bold )
$Login.font = $font_login
$Login.add_click($submit)
$submit = {
$x = $User_Box.text
$Main_Form.Text = $x
$x | out-file c:\x.txt
}
$Main_Form.ShowDialog()
and nothing works in submit
The submit is fine but $x is not working
itried to change the code alot but no benefit
so what should i do to assign the input to a var so i can manipulate it
Thanks in Advance ,
You’re adding a bunch of null objects to your form and you’re adding the variables before you create them. I cleaned it up a little and it’s working for me.
[reflection.assembly]::LoadWithPartialName("system.windows.forms")
#Creat main Form
$Main_Form = New-Object System.Windows.Forms.Form
$Main_Form.width = 500
$Main_Form.Height = 500
$Main_Form.text = " USB Delegator "
#$ICON = New-Object System.Drawing.Icon ("C:\Users\Karem\Desktop\BAD\Kariem.ico")
#$Main_Form.icon = $ICON
#$Main_Form.Controls.Add($User_Box)
#$Main_Form.Controls.Add($User_Label)
#$Main_Form.Controls.Add($Pass_Box)
#$Main_Form.Controls.Add($Pass_Label)
#Creat Uer Name Text Box
$User_Box = New-Object System.Windows.Forms.TextBox
$User_Box.width = 350
$User_Box.Height = 75
$User_Box.top = 200
$User_Box.left = 100
#Creat Login Button
$Login = New-Object System.Windows.Forms.Button
$Login.text = "Login"
$Login.Autosize = $true
$Login.top = 300
$Login.left = 200
$font_login = New-Object System.Drawing.Font ( "Sans Serif " , 9 , [System.Drawing.FontStyle]::Bold )
$Login.font = $font_login
$Login.add_click($submit)
$Main_Form.Controls.Add($User_Box)
$Main_Form.Controls.Add($Login)
$submit = {
$x = $User_Box.Text
$Main_Form.Text = $x
}
$Main_Form.ShowDialog()
Thank you so much Rob Simmers
But i have a quetsion why you removed The Icon
please tell me what do tou mean by null objects , i know i bother you with this questions
but i need to know why
Thanks again