Page 1 of 1

New to this, trying to learn

Posted: Wed Oct 10, 2018 7:44 am
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.

Re: New to this, trying to learn

Posted: Wed Oct 10, 2018 8:01 am
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.

Re: New to this, trying to learn

Posted: Wed Oct 10, 2018 8:51 am
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={
	
	
}



Re: New to this, trying to learn

Posted: Wed Oct 10, 2018 9:02 am
by jvierra
Buttons will trigger when you press enter. Just select the button to push and hit enter.

Re: New to this, trying to learn

Posted: Wed Oct 10, 2018 9:24 am
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.

Re: New to this, trying to learn

Posted: Wed Oct 10, 2018 9:27 am
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.

Re: New to this, trying to learn

Posted: Wed Oct 10, 2018 10:21 am
by jvierra
My best guess is that this is wht you are trying to do:

Review the attached PSF file.