0

I have built a pretty basic form for running New-ADUser and Add-AdGroupMember.

Right now I have it saved as a Function in psm1.

You bring up PS type the function name and the form loads on top of the powershell window. So far so good. But the users I have using it are wanting me to make the cursor active in the Textbox1 field automagically.

Anyone with an idea on somewhere I can find that info?

1 Answer 1

1

Set the focus on the textbox object:

$textbox.Focus()
Sign up to request clarification or add additional context in comments.

5 Comments

$textBox = New-Object System.Windows.Forms.TextBox $textBox.Location = New-Object System.Drawing.Point(10,40) $textBox.Size = New-Object System.Drawing.Size(150,20) $textbox.CharacterCasing="Normal" $textbox.Focused() $form.Controls.Add($textBox)
Worked like a charm. This stuff is fantastic I just need to learn mroe of the terminology so google fu is easier. Thanks a ton.
Well I say that, it worked while executing it from ISE as a ps1 but when I ran it as a function psm1 it did not switch focus.
You may need to add the $textbox.focus() to the form loaded event so that as soon as the form loads it switches the focus.
$form.add_Loaded({ $textbox.Focus() })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.