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.
lldmdb
Posts: 6
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Thu Apr 23, 2020 2:44 am

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.  
  3. #region createtextbox
  4.  
  5.  
  6.  
  7. $u = 1
  8.  
  9. $u1 = 30
  10.  
  11. $nbuser = 20
  12.  
  13. Do
  14.  
  15.     {
  16.  
  17.         #$textboxuser = $textboxuser+$u
  18.  
  19.         $textboxuser = New-Object System.Windows.Forms.TextBox;
  20.  
  21.         $textboxuser.Location = New-Object System.Drawing.Size(16, $u1);
  22.  
  23.         $textboxuser.Name = 'textboxuser' + $u;
  24.  
  25.         $textboxuser.Text = $textboxuser.name;
  26.  
  27.         $textboxuser.Size = New-Object System.Drawing.Size (200, 20);
  28.  
  29.         $textboxuser.Enabled = $false;
  30.  
  31.         $u++
  32.  
  33.         $u1 = $u1 + 30
  34.  
  35.         $gbUSER.Controls.Add($textboxuser);
  36.  
  37.     }while ($u -le $nbuser)
  38.  
  39.    
  40.  
  41.  
  42.  
  43. #endregion createtextbox
  44.  
  45.  
  46.  
  47.  
  48.  
  49. #region WRITETEXTBOX
  50.  
  51. $u = 1
  52.  
  53. $textboxuser_TextChanged = {
  54.  
  55.     $u++
  56.  
  57.     $textboxuser = '$textboxuser'+$u
  58.  
  59.     $textboxuser.Enabled = $true
  60.  
  61. }
  62.  
  63.  
  64.  
  65. #endregion WRITETEXTBOX
  66.  
  67.  
  68.  
  69.  

lldmdb
Posts: 6
Joined: Thu Apr 23, 2020 2:44 am

Re: Powershell : Problem with multiple textbox

Post by lldmdb »

No one can help me?

jvierra
Posts: 14368
Joined: Tue May 22, 2007 9:57 am
Contact:

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: 14368
Joined: Tue May 22, 2007 9:57 am
Contact:

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
Joined: Thu Apr 23, 2020 2:44 am

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: 14368
Joined: Tue May 22, 2007 9:57 am
Contact:

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 11 times

lldmdb
Posts: 6
Joined: Thu Apr 23, 2020 2:44 am

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
Joined: Thu Apr 23, 2020 2:44 am

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: 14368
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Powershell : Problem with multiple textbox

Post by jvierra »

Then use this:
Attachments
Demo-FlowLayout.ps1
(8.52 KiB) Downloaded 9 times

lldmdb
Posts: 6
Joined: Thu Apr 23, 2020 2:44 am

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 222 times
capture1.PNG
capture1.PNG (14.37 KiB) Viewed 222 times

Locked