1

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...

2
  • 1
    A panel is merely a container for other controls. You can only assign a button object (or a link label) to .AcceptButton; presumably, it is fine for such a button to be contained inside a panel. Commented Apr 21 at 17:22
  • 4
    Enable Visual Styles, make the Button Flat. It's going to look like a small panel (kind of). Set the Border size to 0, also the Down and Hover colors. Add an image if that gives it a more modern touch Commented Apr 21 at 18:28

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.