How to set keyboard focus to a TextBox in Powershell

后端 未结 5 1302
醉梦人生
醉梦人生 2021-01-20 17:34

I\'m looking to find out how to automatically set the keyboard focus to a text box in powershell.

I have a script that asks the user to select an option from a drop

相关标签:
5条回答
  • 2021-01-20 17:43

    Try the Select method in case Ficus doesn't work:

    if($textbox.CanFocus)
    {
       $textbox.Focus()
    else
    {
       $textbox.Select()
    }
    
    0 讨论(0)
  • 2021-01-20 17:44

    Works great, but I needed to make the paramValue variable script global (the scope inside the Add_Click routine is not the script scope and the paramValue setting is lost). Using $Global:paramValue worked for me.

    0 讨论(0)
  • 2021-01-20 17:45

    This is an alternative to the answers of @CB and @Shay Levy (none of them worked for me):

    $objForm.Add_Shown( { $objTextBox.Select() })
    
    0 讨论(0)
  • 2021-01-20 17:53

    The code that works with the original post and FOCUS is:

    if ( $objTextBox.CanFocus )
    {
    $objTextBox.Focus()
    }
    else
    {
    $objTextBox.Select()
    }
    
    0 讨论(0)
  • 2021-01-20 17:55

    Following your code, where I can find a dropdown menu, to give focus to textbox when form is shown I've done:

    $objForm.Add_Shown({$objForm.Activate(); $objTextBox.focus()})
    
    0 讨论(0)
提交回复
热议问题