现在的位置: 首页 > 综合 > 正文

Windows Forms 2.0 Programming 读书笔记–Hello, Windows Forms(2)

2013年10月11日 ⁄ 综合 ⁄ 共 1058字 ⁄ 字号 评论关闭
对话框 Dialogs
将ControlBox属性设为false,这样就去掉了系统控制菜单(最大化,最小化和关闭)
set the ControlBox property to false
//使用窗体类的ShowDialog方法将窗体以模式对话框的方式显示其所有者位当前活动窗体
ShowDialog()
//DialogResult枚举用来指示对话框传递给其所有者的返回值,Button类具有DialogResult属性
DialogResult.OK DialogResult.Cancel DialogResult.None
// AcceptButton&CancelButton是窗体类的属性,设置对话框的Enter和Esc==DialogResult.Cancel行为
AcceptButton&CancelButton property
设置以上属性替代了对按钮单击事件的处理
同样内建的校验支持替代了对按钮单击事件的处理
built-in support for validation
首先为窗体添加一个ErrorProvider组件实例errorProvider
_Validating将处理发生在控件即将失去焦点时
private void err_button _Validating(object sender, CancelEventArgs e)
{
     //取消所有可撤销的事件
e.Cancel = true;
//为指定控件显示出错信息
this.errorProvider.SetError(err_button, "error informations here");
}
_Validating在CausesValidation属性为true(触发的控件及触发后焦点所在的控件)时才触发
CausesValidation property
AutoValidate属性为EnablePreventFocusChange时焦点始终在触发校验的控件上,为EnableAllowFocusChange时焦点可在窗体内自由移动,为Diable时校验事件不被触发
AutoValidate (EnablePreventFocusChange/EnableAllowFocusChange/Diable)
当AutoValidate属性EnableAllowFocusChange时可以用Validate方法的返回值来进行校验,
这个方法会依次触发窗体内所有控件的_Validating事件,收集CancelEventArgs的信息,一旦为true则返回false

Validate() 

抱歉!评论已关闭.