How do I specify a form's default and cancel buttons?
You can specify a button is the form's default button (it's automatically selected when the user presses ENTER) by setting its IsDefault property to true. You can specify a button is the form's cancel button (it's automatically selected when the user presses ESCAPE) by setting its IsCancel property to true.
Setting IsDefault or IsCancel to true does not automatically cause the window to close when the ENTER or ESCAPE key is pressed. You must add code to the button's Click event handler to close the window.
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 10/23/10
Comment or report problem with topic
