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.
Locked
User avatar
maximla
Posts: 6
Joined: Tue Oct 09, 2018 3:41 am

New to this, trying to learn

Post by maximla » Wed Oct 10, 2018 7:44 am

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.

User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: New to this, trying to learn

Post by jvierra » Wed Oct 10, 2018 8:01 am

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
Joined: Tue Oct 09, 2018 3:41 am

Re: New to this, trying to learn

Post by maximla » Wed Oct 10, 2018 8:51 am

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={
	
	
}



User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: New to this, trying to learn

Post by jvierra » Wed Oct 10, 2018 9:02 am

Buttons will trigger when you press enter. Just select the button to push and hit enter.

User avatar
maximla
Posts: 6
Joined: Tue Oct 09, 2018 3:41 am

Re: New to this, trying to learn

Post by maximla » Wed Oct 10, 2018 9:24 am

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.

User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: New to this, trying to learn

Post by jvierra » Wed Oct 10, 2018 9:27 am

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.

User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: New to this, trying to learn

Post by jvierra » Wed Oct 10, 2018 10:21 am

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 25 times

Locked