Powershell : Problem with multiple textbox

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.
This topic is 3 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
lldmdb
Posts: 6
Last visit: Wed Apr 29, 2020 10:19 pm

Powershell : Problem with multiple textbox

Post by lldmdb »

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 :
  1.  
  2. #region createtextbox
  3.  
  4. $u = 1
  5. $u1 = 30
  6. $nbuser = 20
  7. Do
  8.     {
  9.         #$textboxuser = $textboxuser+$u
  10.         $textboxuser = New-Object System.Windows.Forms.TextBox;
  11.         $textboxuser.Location = New-Object System.Drawing.Size(16, $u1);
  12.         $textboxuser.Name = 'textboxuser' + $u;
  13.         $textboxuser.Text = $textboxuser.name;
  14.         $textboxuser.Size = New-Object System.Drawing.Size (200, 20);
  15.         $textboxuser.Enabled = $false;
  16.         $u++
  17.         $u1 = $u1 + 30
  18.         $gbUSER.Controls.Add($textboxuser);
  19.     }while ($u -le $nbuser)
  20.    
  21.  
  22. #endregion createtextbox
  23.  
  24.  
  25. #region WRITETEXTBOX
  26. $u = 1
  27. $textboxuser_TextChanged = {
  28.     $u++
  29.     $textboxuser = '$textboxuser'+$u
  30.     $textboxuser.Enabled = $true
  31. }
  32.  
  33. #endregion WRITETEXTBOX
  34.  
  35.  
lldmdb
Posts: 6
Last visit: Wed Apr 29, 2020 10:19 pm

Re: Powershell : Problem with multiple textbox

Post by lldmdb »

No one can help me?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Powershell : Problem with multiple textbox

Post by jvierra »

Please attach the PSF file. The code posted is unreadable, perhaps you can fix it. Your question is also quite vague.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Powershell : Problem with multiple textbox

Post by jvierra »

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
Last visit: Wed Apr 29, 2020 10:19 pm

Re: Powershell : Problem with multiple textbox , How to recover the value of textbox

Post by lldmdb »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Powershell : Problem with multiple textbox

Post by jvierra »

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 84 times
lldmdb
Posts: 6
Last visit: Wed Apr 29, 2020 10:19 pm

Re: Powershell : Problem with multiple textbox

Post by lldmdb »

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
Last visit: Wed Apr 29, 2020 10:19 pm

Re: Powershell : Problem with multiple textbox

Post by lldmdb »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Powershell : Problem with multiple textbox

Post by jvierra »

Then use this:
Attachments
Demo-FlowLayout.ps1
(8.52 KiB) Downloaded 83 times
lldmdb
Posts: 6
Last visit: Wed Apr 29, 2020 10:19 pm

Re: Powershell : Problem with multiple textbox

Post by lldmdb »

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
capture2.PNG (11.77 KiB) Viewed 1739 times
capture1.PNG
capture1.PNG (14.37 KiB) Viewed 1739 times
This topic is 3 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked