powershellwinformsbuttonpanelnew-object

Acceptbutton on Windows.Forms.Panel object


Building a application in winforms with alot of pure powershell functions inside its code. As for now around 6k lines. And i wanted to make the login-logic a more modern touch so i changed the default

$loginButton = New-Object System.Windows.Forms.Button
$form.AcceptButton = $loginButton

to instead use

$loginButton = New-Object Windows.Forms.Panel
$form.Controls.Add($loginButton)

But with this new object, i cant find any information on how to make it accept "ENTER" key as before. Atleast not without having to add my whole code-logic again inside a button press with alot of events inside. And that breaks my whole application...


Solution

  • Using the following giving the button desired effect, thought you had to use a panel in a panel type object. But seems button type works good on panels too as described by resolution comment(s).

    ´$loginButton = New-Object Windows.Forms.Button
    $form.Controls.Add($loginButton)
    $form.AcceptButton = $loginButton´

    Suggested by @Jimi. Thank you also @mklement0