How to make text box accept Return key function (used for Browser) - vb.net

I want to know how to make my Text box (or Address bar) accept the Return/Enter key as a form of submitting a search.
Currently I have a button which submits the search, and not the textbox itself.
Thanks.

Currently I have a button which submits the search, and not the
textbox itself.
Assuming WinForms, set the AcceptButton property of your Form to that Button. Now when you hit enter the button will be automatically clicked for you:
Gets or sets the button on the form that is clicked when the user
presses the ENTER key.

Related

VB setFocus after Typing in Textbox without losing it

I have a login screen where I set the focus to be on the password textbox so that the user can start typing their password without clicking anything.
I want to set the focus to the login button as soon as a character is typed into the password textbox so that the user can just hit Enter when they're done typing in the password.
I don't want to lose focus on the password textbox, but I want the login button to be highlighted so that you can hit Enter.
Right now I have to hit Tab, then Enter for this to work.
Set the Form.Accept Property of your Form to the Button's Name:
Gets or sets the button on the form that is clicked when the user
presses the ENTER key.
Then when the user is done entering their password and hits enter your button will be clicked automatically for them.
Figured it out. Went to the Property Sheet for the Login button and the Default property was set to No. Changed it to Yes and it works perfectly. Thanks.

Triggering Visual Basic Keydown events without a specific function

I'm building on top of code that a previous developer has left me, and he left something that intrigued me quite a bit.
Basically on his menus, he has a TextBox to take in user input and a button next to it to submit the value of the TextBox (for example if the user wanted to select option 1, he would input 1 into the TextBox and click the button). However, the user could also press the Enter key while focusing the TextBox, and it would be treated as the submit button was clicked.
Now this is simple enough to do, but when I check the VB code behind the menu, there's no TextBox_Keydown(...) Handles TextBox.Keydown function anywhere, only the button click event. How is he doing this? He has several menus that are similar and I can't figure out how.
A standard dialog box, if not told to act otherwise, enter does default command button and escape does cancel. In VB look at the properties Default for the command button.
I discovered how he was doing it. He basically mapped the AcceptButton and CancelButton properties of the entire Windows Form to various button functions.

Click differences between text box and a button

On a form where I display data, if the user clicks the text box I open a virtual keyboard (form) and allow them to click buttons to enter data. When this virtual keyboard is opened, if the path to open was from clicking a text box, the first click in the new form (virtual keyboard) is ignored. If the virtual keyboard form is opened from clicking a button (from the first form), it works fine. I can't find a difference between triggering the virtual keyboard form from either control.
It seems to me that your issue is one of focus. When you trigger the virtual keyboard form to open because of the textbox click, you are somehow immediately returning focus to the caller, and not to the newly opened form. Therefore, you might need something as simple as:
myForm.Focus()
...at the end of the code that is opening the form.
I say this because the first click is "ignored", as you say. I would guess that it's actually consuming that first click as a focus event, and then you get the clicks you want registered as you want after that.

Using Enter key to invoke different methods in Mac(objective c)

I am new to Objective c programming. I have created an application which has a UI with two buttons "Cancel" and "Ok". On clicking "Cancel", the application must terminate and clicking "Ok" must perform some task. Everything works fine. I am able to tab between these buttons and can call the required functionality by clicking space button.
All I want to do is, that when focus is on "Cancel" button(using tab key) then on clicking enter button from keyboard, my application should terminate and similarly, when focus is on "Ok" button then clicking enter should perform the desired functionality.
I have even set the 'setKeyEquivalent" property of the "Ok" and "Cancel" button, but I can only set unique keyequivalents. I also tried to read the title or tag value of the buttons and then call the required functionality but it didn't worked too.
Can someone please guide me how can I use enter button to invoke different functions depending upon the selected button in UI.
I think you don't want to set key equivalents for the buttons. You would want to override keyDown: and test for the enter key, then do the appropriate thing depending on which button had focus (which I think you could determine using NSWindow's firstResponder method).

Default Button on Form (VB 2008)

I want to find a way to make a specific button, the form's default button,
I.e. the button that is highlighted when the form opens for the first time.
I tried the AcceptButton property but when I run the program, that does not work.
Any idea?
Thank you in advance,
Tassos
You need to change the AcceptButton property of the containing form.
form1.AcceptButton = button1
Here form1 is the Form whose default button you need to set, and button1 is the name of the Button on that form.
The form's AcceptButton and CancelButton properties define the default behaviour for the Enter and Escape keys, rather than the highlighting.
To highlight the button use the Focus method, but when doing this in the form_load event you will need to call the Select method instead.
btnDefault.Select()
As mentioned in the comments, setting the control to the lowest taborder will achieve the same thing
The answer from 'chk' on 5/2/13 is the correct answer, but is shown as a string which of course is not the way to do it.
Also, in the form's property sheet you can find, under Misc, the property 'AcceptButton'. This will give you a list of buttons on the form - just select the one you want.
The button selected as the AcceptButton will behave as the 'default' button. It will be 'highlighted' with a darker border and will be clicked when you push the Enter key on your keyboard.
Setting up an AcceptButton is different than setting the button's focus. The AcceptButton's click event will be triggered by the Enter key no matter which control has the focus on the form.
You can also do this programmatically.
I have a maintenance form where initially I want the "search" button as the form accept button.
when I'm displaying the field maintenance area, I want the "ok" button to be the accept button.
You simply change this in the appropriate areas in your code to Me.AcceptButton = MyButtonName.