i have a employees form that contain button i i start my project when i want to search i have to click by mouse arrow on search can i choose another option by clicking enter button for search for more details for my project i'm using visual studio 2017 c# forms if any detail is missing please just notice
Asked
Active
Viewed 183 times
3 Answers
0
The easiest way is to set your Form's AcceptButton property to your save button and you will get the 'enter to click' behavior by default. You can either set it through the designer or in you form constructor code:
this.AcceptButton = this.YourSaveButton;
Another option is to set the KeyPreview property to True on the Form. From here you can handle KeyDown events and look for the 'enter' event to handle the button click.

Jurjen
- 1,376
- 12
- 19
0
Wrap the part you want to submit with a Panel
. Then assign a DefaultButton
to that Panel. Now when a user presses enter in a TextBox within that panel, the assigned button will be pressed.
<asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator"
ValidationGroup="myForm"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="myForm" />
</asp:Panel>

VDWWD
- 35,079
- 22
- 62
- 79