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.
This topic is 2 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
monderick
Posts: 7
Last visit: Thu Jan 18, 2024 7:44 am
Answers: 1
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: 8472
Last visit: Mon Mar 18, 2024 2:59 pm
Answers: 19
Been upvoted: 37 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: 7
Last visit: Thu Jan 18, 2024 7:44 am
Answers: 1
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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.
This topic is 2 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked