Search code examples
powershelltextbox

how to get focus in System.Windows.Forms.TextBox powershell?


I've made a window form using powershell.

I've a textbox and i would like to focus.

How to do add a focus to TextBox and make it easier to use ?

here my code

...

    # TextBox
    $textbox = New-Object System.Windows.Forms.TextBox
    $textbox.AutoSize = $true
    $textbox.Location = New-Object System.Drawing.Point(150,125)
    $textbox.Name = 'textbox_sw'
    $textbox.Size = New-Object System.Drawing.Size(220,20)
    $textbox.Text = "Nom de la clef USB ici"
    #$textbox.Focused

...

Solution

  • finally i found it from this post How to set keyboard focus to a TextBox in Powershell So it gives

    $form.Add_Shown({$form.Activate(); $textbox.Focus()}).
    

    Now i've focus on my textbox