Button click event to update text box value

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 1 month, 1 week ago.

  • Author
  • #99109


    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 (
    	$UsernameTextBox.text = "$SurnameTextBox.text"
    	$EmailAddressTextBox.text = "$FirstNameTextBox.text + $SurnameTextBox.text"

    & below is the relevant object code:

    $FirstNameTextBox = New-Object System.Windows.Forms.TextBox
    $PopulateUserDetails = New-Object System.Windows.Forms.Button
    $PopulateUserDetails.Text = 'Populate User Details'

    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?

    Kind regards

  • #99112

    Don Jones

    This is the problem:


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

    "$( $SurnameTextBox.text )"

You must be logged in to reply to this topic.