I'm pretty sure this is a bug of some sort, but if this is by design, then my suggestion would be to change it! :p
If I have one TextBox on a form and have a method that handles the KeyUp Event. In the event, I have code to check for if the user hit enter. When they hit enter, it goes out to a table and looks up to see if what's in the .Text property exists in a particular field in the table and return back true or false. If there is no record, I display a MessageBox telling them there was no record found, then when they hit OK, I set the focus back to the TextBox.
Now, if the user hits the Enter key, because the MessageBox has the focus currently and the OK button is the default button, it closes the MessageBox, however, it immediately opens the same MessageBox back up. You can hit enter as many times as you want, but it keeps come back. If you click the OK button with your mouse, however, the MessageBox goes away and focus is returned to the TextBox
My assumption is that even though you hit the enter key on the MessageBox it was actually registered as if you hit it while in the TextBox.
That's not by design, right Seems like a bug to me. So yah, that's my suggestion. Make it so that doesn't happen!
I even tried just getting rid of the TextBox.Focus() after the MessageBox.Show, but that didn't fix it either!

BUG: Focus for a MessageBox
WylieECoyote
Developr
DinoBob
Kevin M. Owen
Alains
Axerion
Mohit Goel
lifeforms
vishu_gupta
MartinFr-
Create a new form. Put a TextBox on it and nothing else.
Put this code in your form.
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
If e.KeyCode = Keys.Enter Then
MessageBox.Show("Test")
End If
End Sub
Hit Enter in the TextBox, now hit Enter to get hid of the MessageBox. You'll hit it forever and ever until you actually <b>Click</b> the OK Button on the MessageBox. :~
Aaron Sulwer