• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 842
  • Last Modified:

C# Prressing return activates the button rather than having to click it?

I have toyed with most of the properties for a text field and the 'open' button I placed next to it. When I enter my value and press my ENTER KEY (shortcut to mousing over to click the button) I only get a ding noise - I want the default selection to be the same as if someone clicked the 'open' button. It looked so obvious but still DING - enter should activate the button.

Thanks,
Karl66
0
Karl66
Asked:
Karl66
  • 4
  • 3
  • 2
  • +1
2 Solutions
 
Karl66Author Commented:
Should say pressing RETURN of course - they should add an edit function for the first 60 seconds!
0
 
Jaime OlivaresCommented:
Have you tried to implement a KeyPress event for the text and fire the button event from it?
0
 
Karl66Author Commented:
I made a simple form with one button and one text box and no luck. The option to select the button did not appear in the key press dro down.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jaime OlivaresCommented:
is not that simple, there is not a direct option.
You have to create an event method for the KeyPress event by yourself. Do you need help with how to declare the event?
0
 
Karl66Author Commented:
Well.. a little help wouldn't hurt my feelings... thanks
0
 
Jaime OlivaresCommented:
in the designer, select the textbox and go to properties tab, in the top you will find a lightning bolt icon, press to see the events for this control. Locate the "KeyPress" event and double click it to automatically create and empty method to handle this event.
Tell me if you have completed this steps.
0
 
bungHocCommented:
private void Enter_KeyDown(object sender, KeyEventArgs e)
 {
            // Added EnterKey response
            if (e.KeyCode == Keys.Enter)
            {
                // Do whatever you want here: Click button, open folder..
            }
}
0
 
bungHocCommented:
Oh yeah.. and that's after you've already added the even handler.
0
 
andrewjbCommented:
You can set the 'AcceptButton' property of the containing form to be the button, then it automatically 'clicks' it when you hit return.
0
 
Jaime OlivaresCommented:
I think the author will use this feature with many other controls, so using AcceptButton won't be a good idea.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now