1. 为button设置DialogResult property为非None值, 可以关闭父窗口,并使父窗口的DialogResult property返回相应的值。

http://msdn.microsoft.com/en-us/library/system.windows.forms.button.dialogresult(v=vs.110).aspx

Remarks

 

If the DialogResult for this property is set to anything other than None, and if the parent form was displayed through the ShowDialog method, clicking the button closes the parent form without your having to hook up any events. The form's DialogResult property is then set to the DialogResult of the button when the button is clicked.

For example, to create a "Yes/No/Cancel" dialog box, simply add three buttons and set their DialogResult properties to Yes, No, and Cancel.

如果button click里需要做额外的操作或者检查,比如不满足某条件就不关闭父窗口,可以设置DialogResult 为none。

private void buttonOk_Click(object sender, EventArgs e)
{
if (this.comboBox1.SelectedItem == null)
{
MessageBox.Show("Please select the target project!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.DialogResult = DialogResult.None;
}
}

2. Form.AcceptButton, CancelButton Property设置子为子Button, 用户按下Enter, Esc键会触发相应的Button。相当于为Button设置Enter, Esc快捷键。

最新文章

  1. git与github安装、配置、pull、push
  2. git flow工作流实际项目实践
  3. 解析ThreadLocal
  4. asp.net webForm登录授权
  5. RankLib参数翻译
  6. 一个App完成入门篇(二)-搭建主框架
  7. Android笔记——我的Android课的开始
  8. ndk学习7: 使用静态库
  9. 14款经典的MySQL客户端软件
  10. Shanghai InfoSys .NET engineer telephone interview
  11. Kooboo中怎么写Page Plugin -摘自官方文档
  12. CURL传输与获取功能
  13. 桌面环境与桌面搜索Desktop Search tools
  14. MSSQL显错注入爆数字型数据的一点思考
  15. A/C模式 是什么意思啊汽车知识问题_PCauto快问
  16. SQL语句常见DDL/DML/DCL操作部分试题(一)
  17. Navicat 连接Oracle的教程以及注意事项
  18. nginx反向代理(动静分离)
  19. 20180821 Python学习笔记:如何获取当前程序路径
  20. OLAP了解与OLAP引擎——Mondrian入门

热门文章

  1. elementUI动态数据表格(带分页)
  2. java 传入用户名和密码并自动提交表单实现登录到其他系统
  3. springboot2.0(二)
  4. ORA-3136 问题处理
  5. Elasticsearch 9300无法访问,客户端出现NoNodeAvailableException[None of the configured nodes are available:  [{#transport#‐1}{exvgJLR‐RlCNMJy‐hzKtnA}
  6. Nginx 配置参数中文说明
  7. 5.7 zip 版本的安装 以及遇到的坑
  8. linux实操_组管理
  9. nginx 普通用户使用80端口启动nginx
  10. 程序装载:“640K内存”真的不够用么?