Call 'Enter' key to press a button

Welcome Forums General PowerShell Q&A Call 'Enter' key to press a button

Viewing 2 reply threads
  • Author
    • #182142
      Topics: 6
      Replies: 11
      Points: 100
      Rank: Participant

      Can be closed. no solution found

    • #182574
      Topics: 0
      Replies: 24
      Points: 157
      Helping Hand
      Rank: Participant

      Button can be clicked by using the mouse, ENTER key, or SPACEBAR if the button has focus.

      Set the focus using the .Focus() method of the button object.

    • #182586
      Topics: 2
      Replies: 1002
      Points: 2,014
      Helping Hand
      Rank: Community Hero

      This is al generic GUI form design specifics, but not a PowerShell specific thing. WPF/Win, etc GUI (model, SDI, MDI) all have the same kinds of requirements. With all fully documented in the MS docs and other GUI design sites. YOutue is also your friend.

      How to Add a PowerShell GUI Event Handler (Part 1)

      This method puts the event handler inside the parentheses of the $Button.Add_Click call. This method works, but from coding point of view it is not the preferred way, as it make it difficult to find, as the number of controls on the form increases and the complexity grows. Relevant parts are in bold.

      Function Generate-Form {

      Add-Type -AssemblyName System.Windows.Forms
      Add-Type -AssemblyName System.Drawing

      # Build Form
      $Form = New-Object System.Windows.Forms.Form
      $Form.Text = "My Form"
      $Form.Size = New-Object System.Drawing.Size(200,200)
      $Form.StartPosition = "CenterScreen"
      $Form.Topmost = $True

      # Add Button
      $Button = New-Object System.Windows.Forms.Button
      $Button.Location = New-Object System.Drawing.Size(35,35)
      $Button.Size = New-Object System.Drawing.Size(120,23)
      $Button.Text = "Show Dialog Box"


      #Add Button event
      [System.Windows.Forms.MessageBox]::Show("Hello World." , "My Dialog Box")

      #Show the Form
      $form.ShowDialog()| Out-Null

      } #End Function

      #Call the Function

Viewing 2 reply threads
  • The topic ‘Call 'Enter' key to press a button’ is closed to new replies.