PowerShell Forms - Setting Focus

Hello.

I have been working for a while on this PS form to make my day a little easier. I’ve had this really annoying occurrence where, when I run my PS form, if there is text in the results pane of the form, all the text gets highlighted. Here’ s and example:

Now, other controls and objects do present themselves in the form as the menu selection dictates. I guess I’m wondering if there is a way to set focus to something else, maybe just the form itself, so when the form runs the text doesn’t get highlighted?

This highlighting “feature” happens anytime results are returned to the form as well. So If I tell it to get the info of the OS of a server I’m looking at, those results are returned then highlighted as well.

I didn’t put any code in here because I have no clue what you’d need to see. So if you have a need to look at some aspect, let me know and I’ll share that.

You have a couple of options, probably more, but I’ll give you a couple.

  1. You can leave the text box in focus but change the SelectionStart property:
$textBox.SelectionStart = 0
  1. You can set the focus to a different element on the form:
$form.ActiveControl = $button

Hey, Matt.

Thanks for this. Setting the ActiveControl did the trick. I knew there was a way to set that focus, but couldn’t find it in my searches.

Appreciate the help.

Dale

1 Like