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快捷键。

Windows Form, Ok, Cancel button的更多相关文章

  1. windows form (窗体) 之间传值小结

    windows form (窗体) 之间传值小结   windows form (窗体) 之间传值小结 在windows form之间传值,我总结了有四个方法:全局变量.属性.窗体构造函数和deleg ...

  2. Ninject之旅之十二:Ninject在Windows Form程序上的应用(附程序下载)

    摘要: 下面的几篇文章介绍如何使用Ninject创建不同类型的应用系统.包括: Windows Form应用系统 ASP.NET MVC应用系统 ASP.NET Web Form应用系统 尽管对于不同 ...

  3. 在WPF中添加Windows Form控件(包括 ocx控件)

      首先,需要向项目中的reference添加两个dll,一个是.NET库中的System.Windows.Forms,另外一个是WindowsFormsIntegration,它的位置一般是在C:\ ...

  4. 【译】.NET 5. 0 中 Windows Form 的新特性

    自从 Windows Form 在 2018 年底开源并移植到 .NET Core 以来,团队和我们的外部贡献者都在忙于修复旧的漏洞和添加新功能.在这篇文章中,我们将讨论 .NET 5.0 中 Win ...

  5. 如何用Web技术开发Windows Form应用

    现在H5很热,很多互联网公司的产品都采用混合编程,其中各个平台客户端的“壳”为原生控件,但是内容很多都是Web网页,因此可以做出很多炫酷的效果.随着Node.js和Ionic等框架的出现,现在感觉Ja ...

  6. Windows Form 中快捷键设置

    在Windows Form程序中使用带下划线的快捷键只需要进行设置: 就能够工作.

  7. VS2008 Windows Form项目安装包生成详解

    2008 Windows Form项目的发布对有经验的程序员来说,可能不值一提,但对很多新手来说却不知道如何操作,因为在很多关于Visual Studio的书籍中也没有相关介绍,权威如<C# 2 ...

  8. VISUAL STUDIO 2008 WINDOWS FORM项目发布生成安装包详解(转)

    转自:http://www.cnblogs.com/killerofyang/archive/2012/05/31/2529193.html Visual Studio 2008 Windows Fo ...

  9. C# Adding Hyperlink to Windows Form z

    When creating a Windows form in C#, we would like to create a hyperlink so that when the user click ...

随机推荐

  1. 关闭google默认打开翻译提醒

    关闭google默认打开翻译提醒 在header中添加以下代码: <meta name="google" content="notranslate" /& ...

  2. Ajax的学习

    AJAX的学习 AJAX的简介 AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. AJAX ...

  3. ajax:用于创建快速动态网页的技术

    ajax是一种用于创建快速动态网页的技术. 异步的javascript和XML(JSON),主要是完成一个局部刷新. 异步:你传输吧,我先干我自个儿的事,你传好了告诉我一声 同步:你传输,我停下活儿看 ...

  4. 运行 jar 的问题

    lib stwe.jar 同目录

  5. leetcode-8.atoi · string *

    题面 原题挺长的,还是英文,就不抄了,

  6. ubuntu 14.04 登录 界面 root

    打开终端. sudo gedit /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf 在弹出的编辑框里输入:greeter-show-manual-log ...

  7. KVM虚拟机高级设置——10 快照、克隆、替换磁盘

    查看虚拟机磁盘文件 [root@CentOS2 ~]# cd /var/lib/libvirt/images/ [root@CentOS2 images]# ll -h total 13G -rw-r ...

  8. idou老师教你学Istio 28:istio-proxy check 的缓存

    功能概述 istio-proxy主要的功能是连接istio的控制面组件和envoy之间的交互,其中check的功能是将envoy收集的attributes信息上报给mixer,在istio中有几十种a ...

  9. Python多线程爬虫爬取网页图片

    临近期末考试,但是根本不想复习!啊啊啊啊啊啊啊!!!! 于是做了一个爬虫,网址为 https://yande.re,网页图片为动漫美图(图片带点颜色........宅男福利 github项目地址为:h ...

  10. less避免编译

    less里面有一个避免编译,有时候我们需要输出一些不正确的css语法或者使用less不认识的专有语法.要输出这样的值我们可以在字符串前加上一个~ /*避免编译*/ .test_03{ width: 3 ...