none
Focus setzen RRS feed

  • Frage

  • Hallo, wie erreiche ich es, dass der Cursor im Eingabefeld steht und ich sofort nach dem Scriptstart meinen Text eingeben kann?

    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
        [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 
        $objForm = New-Object System.Windows.Forms.Form 
        $objForm.Text = "LBBW DSM Support"
        $objForm.Size = New-Object System.Drawing.Size(300,200) 
        $objForm.StartPosition = "CenterScreen"
        $objForm.KeyPreview = $True
        $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") 
            {$x=$objTextBox.Text;$objForm.Close()}})
        $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") 
            {$objForm.Close()}})
        $OKButton = New-Object System.Windows.Forms.Button
        $OKButton.Location = New-Object System.Drawing.Size(75,120)
        $OKButton.Size = New-Object System.Drawing.Size(75,23)
        $OKButton.Text = "Senden"
        $OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
        $objForm.Controls.Add($OKButton)
        $CancelButton = New-Object System.Windows.Forms.Button
        $CancelButton.Location = New-Object System.Drawing.Size(150,120)
        $CancelButton.Size = New-Object System.Drawing.Size(75,23)
        $CancelButton.Text = "Abbrechen"
        $CancelButton.Add_Click({$objForm.Close()})
        $objForm.Controls.Add($CancelButton)
        $objLabel = New-Object System.Windows.Forms.Label
        $objLabel.Location = New-Object System.Drawing.Size(10,20) 
        $objLabel.Size = New-Object System.Drawing.Size(280,20) 
        $objLabel.Text = "Bitte den Computernamen eingeben:"
        $objForm.Controls.Add($objLabel) 
        $objTextBox = New-Object System.Windows.Forms.TextBox 
        $objTextBox.Location = New-Object System.Drawing.Size(10,40) 
        $objTextBox.Size = New-Object System.Drawing.Size(260,20) 
        $objForm.Controls.Add($objTextBox) 
        $objForm.Topmost = $True
        $objForm.Add_Shown({$objForm.Activate()})
        [void] $objForm.ShowDialog()
        $computername = $x


    IT Berater

    Freitag, 15. November 2013 11:45

Antworten

  • Schon gefunden:

    $objForm.Add_Shown({$objForm.Activate(); $objTextBox.focus()})

    nach dem Eingabefeld setzen und schon funktioniert es.


    IT Berater

    • Als Antwort markiert NBC2009 Freitag, 15. November 2013 11:50
    Freitag, 15. November 2013 11:49