Problem with Button and Pressing Enter

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problem with Button and Pressing Enetr

Post by jvierra »

Not at all the same. The button is never clicked. The form handles the keystrokes.

The point is it can only be done the way I posted. Any other method will not work in most scenarios.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Problem with Button and Pressing Enetr

Post by dan.potter »

"Thats the reason i want to "click" the button "uebernhmen + ..." with the enter key"

I guess I'm still lost, why can't we click the button with the enter key? see example, if the button is focused the enter key does the click event each time it is pressed.
sapienexamples.psf
(26.41 KiB) Downloaded 113 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problem with Button and Pressing Enetr

Post by jvierra »

Hw is saying he wants the button function to occur when he hits the enter key. I told him as he describes it, it cannot be done. If the button is in focus it can be activated in code or we can use the space bar to click it. TO make the enter key work we must assign the button as the forms "AcceptButton"

The code I posted does exactly what he wants. It allows enter to be used to enter text then a tab enter will operate the button. The button should not have any code. Place code in the windows "closing" event.

If you are curious about how forms work then look at the MSDN site on designing with Windows forms. There are a lot of explanations about how events work and info on standard way to do most things.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Problem with Button and Pressing Enetr

Post by dan.potter »

That's exactly what I did without any special code or design configuration. Enter in the textbox adds stuff to the listbox. Tab then enter does the click event on the button. We can assign the dialogresult or script form.close(). Either way the enter key is the same as the mouse click on the button. This would be a whole lot easier to understand with code :D Perhaps we're missing an event?
User avatar
NuBreed
Posts: 11
Last visit: Thu Aug 11, 2016 1:58 am

Re: Problem with Button and Pressing Enetr

Post by NuBreed »

oh my goodness....what a shame....your posts made me realize what my problem WAS

i used button_MOUSEClick instead of button_Click......damnit, what a stupid mistake, the name already says it....
now i understand why you couldnt understand my problem, because i was asking for a basic function....

and you are right jvierra, i urgently need to become familiar with the forms.
thank u so much guys, nearly 35 posts for my problems, u are so fing awesome..


best wishes and thanks a lot u 2 :)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problem with Button and Pressing Enetr

Post by jvierra »

Glad something was useful. Have a PosH time.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Problem with Button and Pressing Enter

Post by dan.potter »

It happens :D There was an earlier version of PS studio that had a bug in which it removed all the checkboxes for the events in the designer on export but kept the code. Left me scratching my head lots of times.

FYI double clicking the control in the designer automatically inserts the default event.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problem with Button and Pressing Enter

Post by jvierra »

Right click on a control in the toolbox. Right click on a control object in the script editor. Right click on a control property in the script editor.
This topic is 7 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked