Output text to a text box....

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 7 years and 4 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
Diener
Posts: 3
Last visit: Tue Nov 06, 2018 6:05 am

Output text to a text box....

Post by Diener »

Before someone suggests it, I have already read the following link: https://www.sapien.com/blog/2014/12/15/ ... tion-copy/

My confusion is this... how do I get the output of my button press (which runs a simple function) to actually output into my textbox? Here's my script that I'm using to test out functionality of Studio. I have the $textboxresults.text = blah blah blah but that doesn't seem to do anything at all....

$form1_Load={
#TODO: Initialize Form Controls here
Import-Module ActiveDirectory
}

$buttonGetUser_Click= {
#TODO: Place custom script here
$GetUser = Get-User
$textboxResults.text = $GetUser

Function Get-User
{
[CmdLetBinding()]
Param ([Parameter(Mandatory = $true)]
[System.String]$user)
Get-Aduser -filter "Name -like '$user*'"
}

Get-User
}


$textbox1_TextChanged={
#TODO: Place custom script here

}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Output text to a text box....

Post by jvierra »

PowerShell returns objects. A textbox only display strings.

$textbox1.Text = Get-Aduser -filter "Name -like '$user*'" | select -expand name
User avatar
Diener
Posts: 3
Last visit: Tue Nov 06, 2018 6:05 am

Re: Output text to a text box....

Post by Diener »

jvierra wrote:PowerShell returns objects. A textbox only display strings.

$textbox1.Text = Get-Aduser -filter "Name -like '$user*'" | select -expand name
So how do I have this trigger from a button click? And can I just define a function and have the code like...

$textbox1.Text = Get-User where Get-User is my function defined earlier in the script?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Output text to a text box....

Post by jvierra »

Why would you use a function for two lines of code. A button click event is a function.

Just place the code in the button click block.
This topic is 7 years and 4 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