请教:在帮助文件中窗口BeforeClose提到不允许新输入的值为空,但保留原有的值(即当修改该时间时,若有新值输入,记录新值;若输入空值时,保留原有的值时,代码如何写)
BeforeClose
在关闭窗口前执行。
e参数属性:
Form: 表示要关闭的窗口
Cancel: 逻辑型,设为True,将禁止关闭窗口。
CloseMode: 整数型,如果是通过Form的Close方法关闭窗口,则返回1,否则返回0。
如果任何时候Cancel参数都返回True的话,那么窗口将永远不能关闭,直到强行中止进程,所以在代码中使用Cancel参数的时候,一定要慎重。
示例
请在窗口中加入两个DateTimePicker(日期输入框),分别命名为StartDate和EndDate。
然后将BeforeClose事件代码设为:
Dim sd As WinForm.DateTimePicker
Dim ed As WinForm.DateTimePicker
sd = e.Form.Controls("StartDate")
ed = e.Form.Controls("EndDate")
If sd.Value Is Nothing OrElse ed.Value Is Nothing Then
MessageBox.Show("请输入起始日期和终止日期!","提示", MessageBoxButtons.OK ,MessageBoxIcon.Information)
e.Cancel = True
Else
请教保留原值的代码怎写
End If