Multiple Textbox

Welcome Forums General PowerShell Q&A Multiple Textbox

  • This topic has 5 replies, 3 voices, and was last updated 1 month ago by
    Participant
    .
Viewing 4 reply threads
  • Author
    Posts
    • #221736
      Participant
      Topics: 1
      Replies: 2
      Points: 18
      Rank: Member

      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
    • #221838
      Participant
      Topics: 12
      Replies: 1622
      Points: 2,560
      Helping Hand
      Rank: Community Hero

      Take a look at $this thread:

      ContextMenuStrip in Loop

    • #222069
      Participant
      Topics: 1
      Replies: 2
      Points: 18
      Rank: Member

      Hello;
      thanks for this help.
      On the other hand ; how do i select this or that textbox.
      example: I want all textboxes to be disabled and only the first to be active.

      The next one will be activated only when I have at least 5 characters in the previous one.

      What I can’t do is select the desired textbox because I would need the following variables.

      #region createtextbox
      $u = 1
      $u1 = 30
      $nbuser = 10
      #######
      for ($u = 0; $u -lt $nbuser; $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;
      	$u1 = $u1 + 30
      	$gbUSER.Controls.Add($textboxuser);
      }
      
      #FirstTEXTBOX..
      ##??????????????????????How can I select the first textbox or the second ... etc?????????????????????
      
      $u = 1
      $control = $gbUSER.Controls
      
      $control.Item($u)
      $textboxuser.Name ='$textboxuser'+$u
      $textboxuser.Enabled= $true
      
      #????????????????????????????????????????????????
      #endregion SuivantversONGLET
      
      #region ONGLET
      $u = 1
      $textboxuser_TextChanged = {
      	$u++
      	$textboxuser = '$textboxuser'+$u
      	$textboxuser.Enabled = $true
      }
      
      #endregion createtextbox
      
      #region WRITETEXTBOX
      
      #endregion WRITETEXTBOX

       

    • #223422
      Participant
      Topics: 3
      Replies: 340
      Points: 1,120
      Helping Hand
      Rank: Community Hero

      Maybe I’m misunderstanding, but couldn’t you “select” the text boxes by their names? Of course you would want to give them better names.

      $textboxuser.Name ='$textboxuser'+$u

      So you are effectively naming these $textboxuser1, $textboxuser2, etc. I would remove that $ – it is a special reserved character in powershell. If you remove that dollar sign, you’ll end up with textboxuser1, textboxuser2, etc. If you intended to expand $textboxuser, you should first take a look at what that contains. Now knowing their names, you should be able to grab that control by name. Otherwise, you could use something like this to gather a list of all your textbox controls.

      $textcontrols = foreach($control in $groupBox.Controls){
          if($control -is [System.Windows.Forms.TextBox]){
              $control
          }
      }
      

      Once you have a collection of them, you can check the length of the first textbox and if greater than or equal to 5, enable the rest.

      for($i = 1,$i -lt $textcontrols.count,$i++){
          if($textcontrols[0].length -ge 5){
              $textcontrols[$i].enabled = $true
          }
      }
      

      I hope this helps.

    • #224007
      Participant
      Topics: 1
      Replies: 2
      Points: 18
      Rank: Member

      Thank you

Viewing 4 reply threads
  • You must be logged in to reply to this topic.