设定如下

this.AcceptButton = this.btnOK;
this.CancelButton = this.btnCancel;
接下来设定

this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
但是在运行时点这两个按钮或按回车键,ESC键都应该可以关闭窗口,但结果都没动作??
查了N久才找到问题点.
原来要使用ShowDialog()显示窗体以上设定才有效.使用Show()时无效.不知道微软为什么要这样....