I have a dialog that I show with .ShowDialog(). It has an OK button and a Cancel button; the OK button also has an event handler.
.ShowDialog()
I want to
This doesn't directly answer your question (other already have), but from a usability point of view, I would prefer the offending button be disabled while the input is not valid.