Button click event to update text box value

Welcome Forums General PowerShell Q&A Button click event to update text box value

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
7 months ago.

  • Author
    Posts
  • #99109

    Participant
    Points: 0
    Rank: Member

    Hello,
    I am quite new to Powershell so apologies if the below is of poor quality/anything missed. I am trying to update a textbox value on button click which will be the result of data entered into different text boxes. My current function is producing ".text" in the GUI and not the .text property of the text box objects that I want to show.

    Below is the function:

    function PopulateUserDetails
    {
            param (
    	$FirstNameTextBox,
    	$SurnameTextBox
    	)
    	
    	$UsernameTextBox.text = "$SurnameTextBox.text"
    	$EmailAddressTextBox.text = "$FirstNameTextBox.text + $SurnameTextBox.text"
    }
    

    & below is the relevant object code:

    $FirstNameTextBox = New-Object System.Windows.Forms.TextBox
    $form.Controls.Add($FirstNameTextBox)
    
    $PopulateUserDetails = New-Object System.Windows.Forms.Button
    $PopulateUserDetails.Text = 'Populate User Details'
    $PopulateUserDetails.add_Click({PopulateUserDetails})
    $form.Controls.Add($PopulateUserDetails)
    

    Where surname text box has the same properties as first name text box.

    From the code above, I want my statement to when button click "Populate user details", update the user name and email address text boxes to $Firstname and $Firstname+$surname respectively, but it is showing as ".text" and ".text .text". How can I reference the firstname and surname values that the user has entered? Also, if achievable, is there a way to 'Auto' update the value of the textbox in real-time as the user is entering them?

    Thanks
    Kind regards

  • #99112

    Keymaster
    Points: 1,624
    Helping HandTeam Member
    Rank: Community Hero

    This is the problem:

    "$SurnameTextBox.text"

    Only $SurnameTextBox is read as a variable name. Use a subexpression instead:

    "$( $SurnameTextBox.text )"

The topic ‘Button click event to update text box value’ is closed to new replies.