New to this, trying to learn

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 5 years and 5 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
maximla
Posts: 6
Last visit: Mon Apr 29, 2019 12:52 am

New to this, trying to learn

Post by maximla »

Hi! I hope my question is ok for the forums. I'm quite new to dealing with windows forms, so here we go:
I made a simple "Empty Form" using the template.
From there I used the toolbox and added one button, one textbox (to be used for input), and another textbox (for displaying results from my command).

So the code I got so far is:

Code: Select all

$formLocalUserLookup_Load={
	
	
}

$searchbutton_Click={
	
	$global:user = Get-LocalUser $inputuser
}

$usersearchbox_TextChanged={
	
	$global:inputuser = $usersearchbox.Text
}

$textbox1_TextChanged={
	
	#This is where I can't get it to work
	$textbox1.Text = $user
}
So my $searchbutton is supposed to take the .text from $usersearchbox and use it with get-localuser.

That seems to work, because I get errors if I type in a user that dosent exist and press my button.
But I can't seem to get the results into my $textbox1.

I would appreciate if anyone could show me how to get this right. And maybe link to some documentation I can read relating to how new I am to this.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: New to this, trying to learn

Post by jvierra »

I suggest starting with the "spotlight" articles. They are linked on the toolbox item in the "right-click" menu.

You should also take time to review the product manual on the "help" ribbon.
When assigning objects to a string property the results may not be viewable. Try assigning a property of the object.
User avatar
maximla
Posts: 6
Last visit: Mon Apr 29, 2019 12:52 am

Re: New to this, trying to learn

Post by maximla »

Thanks for the reply!

I figured it out.
Now I'm trying to figure out how to trigger the button with a Enter press on the keyboard.

Code so far:

Code: Select all

$formLocalUserLookup_Load={
	
	
}


$usersearchbox_KeyPress = [System.Windows.Forms.KeyPressEventHandler]{
	#Event Argument: $_ = [System.Windows.Forms.KeyPressEventArgs]
	#TODO: Place custom script here
	if ($_.KeyCode -eq 'Enter')
	{
		&$searchbutton_Click
	}
	
}


$searchbutton_Click={
	$textbox1.Clear
	$global:user = Get-LocalUser $inputuser
	$user = $user | Select-Object ($user.PSObject.Properties.Where{ $null -ne $_.Value }.Name) | Format-List | Out-String
	$textbox1.Text = $user
	
}



$usersearchbox_TextChanged={
	
	$global:inputuser = $usersearchbox.Text
}

$textbox1_TextChanged={
	
	
}


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

Re: New to this, trying to learn

Post by jvierra »

Buttons will trigger when you press enter. Just select the button to push and hit enter.
User avatar
maximla
Posts: 6
Last visit: Mon Apr 29, 2019 12:52 am

Re: New to this, trying to learn

Post by maximla »

What do you mean "select the button to push"?
I want to enter text to my textbox, press enter, and the _click event should start.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: New to this, trying to learn

Post by jvierra »

The click event will run any time the button is clicked. I don't seem to be able to understand what you are trying to ask.

Please read the spotlight articles referenced above. They will help you understand how each control works.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: New to this, trying to learn

Post by jvierra »

My best guess is that this is wht you are trying to do:

Review the attached PSF file.
Attachments
Demo-ButtonsTOText.psf
(22.49 KiB) Downloaded 90 times
This topic is 5 years and 5 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