Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
lldmdb
Posts: 6 Joined: Thu Apr 23, 2020 2:44 am
Post
by lldmdb » Thu Apr 23, 2020 4:19 am
Hello,
I’m coming for help. For several days I have been stuck on my problem. I work with SAPIUEN Powershell Studio 2018 software.
I would like according to a variable to create the equivalent number of textbox.
(region createtextbox)
Then I only want the first textbox to be activated. the next can only be if the previous one has at least 5 characters. and when all my textboxes are filled, then I have a button that appears.
(region WRITETEXTBOX)
The first point is good, I can’t get there on the second and especially how I can select this or that textbox value?
Thank you in advance for your assistance.
My program :
#region createtextbox
$u = 1
$u1 = 30
$nbuser = 20
Do
{
#$textboxuser = $textboxuser+$u
$textboxuser = New-Object System.Windows.Forms.TextBox;
$textboxuser .Location = New-Object System.Drawing.Size( 16 , $u1 ) ;
$textboxuser .Name = 'textboxuser' + $u ;
$textboxuser .Text = $textboxuser .name;
$textboxuser .Size = New-Object System.Drawing.Size ( 200 , 20 ) ;
$textboxuser .Enabled = $false ;
$u ++
$u1 = $u1 + 30
$gbUSER .Controls.Add( $textboxuser ) ;
} while ( $u -le $nbuser )
#endregion createtextbox
#region WRITETEXTBOX
$u = 1
$textboxuser_TextChanged = {
$u ++
$textboxuser = '$textboxuser' + $u
$textboxuser .Enabled = $true
}
#endregion WRITETEXTBOX
lldmdb
Posts: 6 Joined: Thu Apr 23, 2020 2:44 am
Post
by lldmdb » Fri Apr 24, 2020 12:38 am
No one can help me?
jvierra
Posts: 14668 Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:
Post
by jvierra » Fri Apr 24, 2020 12:56 am
Please attach the PSF file. The code posted is unreadable, perhaps you can fix it. Your question is also quite vague.
jvierra
Posts: 14668 Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:
Post
by jvierra » Fri Apr 24, 2020 1:06 am
This is how to post code and how to do the increments and find the box by name:
Code: Select all
for($u = 1;$u -lt 30;$u++){
$textboxuser = New-Object System.Windows.Forms.TextBox
$textboxuser.Location = "16,$($ul + (30 * ($u - 1)))"
$textboxuser.Name = "textboxuser$u"
$textboxuser.Text = $textboxuser.name
$textboxuser.Size = '200, 20'
$textboxuser.Enabled = $false
$gbUSER.Controls.Add($textboxuser)
}
$textboxuser_TextChanged = {
$u = 1 # ????
$gbUSER.Controls["textboxuser$u"].Enabled = $true
}
lldmdb
Posts: 6 Joined: Thu Apr 23, 2020 2:44 am
Post
by lldmdb » Fri Apr 24, 2020 1:13 am
thank you very much for this command which I did not know., I will be able to continue.
Last edited by
lldmdb on Fri Apr 24, 2020 1:31 am, edited 1 time in total.
jvierra
Posts: 14668 Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:
Post
by jvierra » Fri Apr 24, 2020 1:37 am
Play with this for a while. It will help you understand how this is done in forms.
Attachments
Demo-FlowLayout.psf
(44.57 KiB) Downloaded 45 times
lldmdb
Posts: 6 Joined: Thu Apr 23, 2020 2:44 am
Post
by lldmdb » Fri Apr 24, 2020 2:04 am
jvierra wrote: ↑ Fri Apr 24, 2020 1:37 am
Play with this for a while. It will help you understand how this is done in forms.
I'm going to play with this. and come back to see you if I still struggle. Thanks for your help.
lldmdb
Posts: 6 Joined: Thu Apr 23, 2020 2:44 am
Post
by lldmdb » Fri Apr 24, 2020 2:08 am
jvierra wrote: ↑ Fri Apr 24, 2020 1:37 am
Play with this for a while. It will help you understand how this is done in forms.
I cannot read it, because my version must be less recent than yours. I'm in sapien 2018.
lldmdb
Posts: 6 Joined: Thu Apr 23, 2020 2:44 am
Post
by lldmdb » Sat Apr 25, 2020 1:34 am
Hello, I have another question. thanks again for the example it helped me a lot.
According to the piece of my program below, how to do it to execute the function of checkboxes checked or not. I have two checkboxes that go hand in hand. when one is checked, the other cannot be checked and vice versa. I put in addition two captures as an example.
thank you in advance
Code: Select all
[attachment=0]capture2.PNG[/attachment][attachment=1]capture1.PNG[/attachment]
$nbuser = $textboxNBUSER.Text
$lb1 = 223
for ($lb = 1; $lb -le $nbuser; $lb++)
{
$labeluser = New-Object System.Windows.Forms.Label
$labeluser.Location = "20, $($lb1 + (30 * ($lb - 1)))"
$labeluser.Name = "labeluser$lb"
$labeluser.Size = '150, 20'
$labeluser.Text = $gbUSER.Controls["textboxuser$lb"].Text
$groupbox1.Controls.Add($labeluser)
$checkboxandroid = New-Object System.Windows.Forms.CheckBox
$checkboxandroid.Location = "209, $($lb1 + (30 * ($lb - 1)))"
$checkboxandroid.Name = "checkboxandroid$lb"
$checkboxandroid.Size = '28, 24'
$checkboxandroid.Checked = $true
$groupbox1.Controls.Add($checkboxandroid)
$checkboxlinux = New-Object System.Windows.Forms.CheckBox
$checkboxlinux.Location = "309, $($lb1 + (30 * ($lb - 1)))"
$checkboxlinux.Name = "checkboxlinux$lb"
$checkboxlinux.Size = '28, 24'
$groupbox1.Controls.Add($checkboxlinux)
}
############ CHOICE ANDROID OU LINUX FOR THE CLIENT
$chklinux = $groupbox1.Controls["checkboxlinux$lb"].Text
$chkandroid = $groupbox1.Controls["checkboxandroid$lb"].Text
$chklinux_CheckedChanged = {
?????
}
Attachments
capture2.PNG (11.77 KiB) Viewed 938 times
capture1.PNG (14.37 KiB) Viewed 938 times