I have a popup window, where in the main form, i have something like this

If _frmDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
 ' Do something here
end if

My current issue is, I would like the text box in the popup windows will fire the event of "dialogResult.ok"
when the user press the "enter key", means they do not need to use mouse to click on the "OK"

Please advice.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


I think you could solve you problem like this:

Inside the TextBox_KeyUp event :

    If e.KeyCode = Keys.Enter Then
      Me.DialogResult = Windows.Forms.DialogResult.OK
    End If

Otherwise, I suggest you to set the DialogResult member of the CommandButton (ok) to OK and use the code :

    If e.KeyCode = Keys.Enter Then
    End If

Hope this helps!

Mike TomlinsonMiddle School Assistant TeacherCommented:
So you have an "OK" button on your form?...Let's assume it is called "btnOK".

In DESIGN VIEW, select the FORM.  (Make sure you have the Form seleted and not any of the controls on it!)
Now set the AcceptButton() Property DropDown to "btnOK".
Do the same thing for the CancelButton() Property if you have a Cancel button as well.

That's're done.  No code is neeed!

btnOK will be clicked when the user presses Enter.
btnCancel will be clicked when the user presses Escape.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cybehAuthor Commented:
Simple and clean !!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.