Как я могу инициировать кнопку по умолчанию на форме, не нажимая его (winforms)?

Хорошо я нашел решение, которое работает, хотя мне действительно не нравится оно. Я должен был удалить .designer.cs файл, тогда воссоздают пустой файл с тем же именем. Когда я возвратился в и сохранил aspx файл снова, файл разработчика был повторно создан.

Изворотливый!

6
задан Simon P Stevens 8 July 2009 в 13:08
поделиться

5 ответов

Саймон П. Стивенс дал вам наиболее адекватный ответ.

Я бы просто добавил, что у вас также есть возможность установить CancelButton формы, на которой будет происходить щелчок. активируется при нажатии клавиши escape ESC .

Краткое описание

Введите -> AcceptButton

Esc -> CancelButton

4
ответ дан 8 December 2019 в 05:23
поделиться

Set the button to be the accept button on the form. You can do this by setting the forms "AcceptButton" property to be the button you want to trigger. This will make an enter key press trigger the button.

18
ответ дан 8 December 2019 в 05:23
поделиться

If you don't want the button to be the default you can hook both TextBoxes KeyPress events to same handler then check if Enter was pressed using KeyEventArgs.KeyCode.

0
ответ дан 8 December 2019 в 05:23
поделиться

If you need to be able to navigate the form without the mouse, you'll want to make sure your tab stops are set correctly. I would set Login Id as the first, password as the second, and your submit button as the third. Then the user can navigate easily among them. IIRC, the default behavior of buttons is to fire off the On_Click event if the Enter key is pressed while the button has focus.

0
ответ дан 8 December 2019 в 05:23
поделиться

используйте

buttonName. PerformClick () ;

1
ответ дан 8 December 2019 в 05:23
поделиться
Другие вопросы по тегам:

Похожие вопросы: