textbox appendtext

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.
Locked
User avatar
monderick
Posts: 2
Last visit: Tue Jun 15, 2021 5:35 pm
Has voted: 1 time

textbox appendtext

Post by monderick »

I searched for a solution for my issue with AppendText but didn't find anything.
trying to append the input from multiple text boxes into a "summary" text box but it is adding the below text marked in red for each input
i'm missing something obvious to avoid this and prevent that text from appearing, thanks for any help!


$FirstName_TextChanged = {
$firstname = $FirstName.text
}

$LastName_TextChanged={
$lastname = $LastName.text
}

Code: Select all

$buttonProvision_Click={
	#TODO: Place custom script here
	if ($radiobuttonInvited.Checked -eq $true)
	{
		$usertype = "invited"
	}
	$results.ForeColor = 'Green'
	$results.Text = "User type is '$usertype'`r`n"
	$results.AppendText("First Name is '$FirstName'`r`n")
	$results.AppendText("Last Name is '$LastName'")
}
contents of the "summary" text box:
User type is 'invited'
First Name is 'System.Windows.Forms.TextBox, Text: John'
Last Name is 'System.Windows.Forms.TextBox, Text: Smith'
by Alexander Riedel » Thu Jun 10, 2021 9:26 am
PowerShell is not case sensitive.

So $lastname is the same as $LastName
$lastname = $LastName.text
So this statement assigns the text in the $LastName object to the object itself.
That'll screw things up royally.

I would recommend to name things a little differently.

I name controls with a 'Ctl' suffix. So
$LastName would become $LastNameCtl

The variable you use to assign the content to is a string. So you could name it
$strLastName or $LastNameStr to make sure when you look at the code you know what is what.
I personally use a type prefix but a suffix for generic things like 'Control', but that is a personal thing for you to develop.
Go to full post

User avatar
Alexander Riedel
Posts: 7792
Last visit: Thu Oct 28, 2021 8:14 am
Answers: 6
Been upvoted: 11 times

Re: textbox appendtext

Post by Alexander Riedel »

PowerShell is not case sensitive.

So $lastname is the same as $LastName
$lastname = $LastName.text
So this statement assigns the text in the $LastName object to the object itself.
That'll screw things up royally.

I would recommend to name things a little differently.

I name controls with a 'Ctl' suffix. So
$LastName would become $LastNameCtl

The variable you use to assign the content to is a string. So you could name it
$strLastName or $LastNameStr to make sure when you look at the code you know what is what.
I personally use a type prefix but a suffix for generic things like 'Control', but that is a personal thing for you to develop.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
monderick
Posts: 2
Last visit: Tue Jun 15, 2021 5:35 pm
Has voted: 1 time

Re: textbox appendtext

Post by monderick »

thanks, Alexander! pointed me in the correct direction and output is as expected now
made no alterations under the individual controls

$buttonProvision_Click = {
$FirstNameSTR = $FirstNameCTL.text
$LastNameSTR = $LastNameCTL.text

#TODO: Place custom script here
if ($radiobuttonInvited.Checked -eq $true)
{
$usertype = "invited"
}
$results.ForeColor = 'Green'
$results.Text = "User type is '$usertype'`r`n"
$results.AppendText("First Name is '$FirstNameSTR'`r`n")
$results.AppendText("Last Name is '$LastNameSTR'")

}


contents of the "summary" text box now:
User type is 'invited'
First Name is 'John'
Last Name is 'Smith'

jvierra
Posts: 14954
Last visit: Thu Oct 28, 2021 11:57 am
Answers: 14
Has voted: 3 times
Been upvoted: 11 times

Re: textbox appendtext

Post by jvierra »

This is how to dereference an object:
  1. $results.Lines += 'First Name is ' + $FirstName.Text
  2. $results.Lines += 'Last Name is ' + $LastName.Text
This automatically adds a linebreak.

Locked