Windows.Forms.DialogResult.OK

Hi,

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.
LVL 1
cybehAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle 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 it...you're done.  No code is neeed!

btnOK will be clicked when the user presses Enter.
btnCancel will be clicked when the user presses Escape.
0
 
CarlVerretCommented:
Hi,

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
      Me.Close()
    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
            Me.Close()
    End If

Hope this helps!

Carl
0
 
cybehAuthor Commented:
Simple and clean !!
0
All Courses

From novice to tech pro — start learning today.