如何在关闭之前捕获未保存的数据? [英] How to catch the unsaved data before closing?
问题描述
我需要确保用户无法关闭(使用X)表单,然后再将
保存在其上。我应该在哪个表单事件中编写控件代码?
谢谢,
-Delen
I need to make sure that the user cannot close (using "X") the form before
saving the data on it. Which form event should I write the control code in?
Thank you,
-Delen
推荐答案
查看表单Closing事件。
定义一个表单级别var,如果表单数据很脏,可以将其设置为tru
并在事件中触发...
私有子Form1_Closing(ByVal发件人作为对象,_
ByVal e As
System.ComponentModel.CancelEventArgs)_
处理MyBase.Closing
如果(isDirty = True)那么
e。取消=真
结束如果
End Sub
" Dursun" <都**** @ discussions.microsoft.com>在消息中写道
news:9C ********************************** @ microsof t.com ...
Look at the forms Closing event.
Define a form level var that you can set to tru if your forms data is dirty
and trigger of that in the event...
Private Sub Form1_Closing(ByVal sender As Object, _
ByVal e As
System.ComponentModel.CancelEventArgs) _
Handles MyBase.Closing
If (isDirty = True) Then
e.Cancel = True
End If
End Sub
"Dursun" <Du****@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
我需要确保用户在保存表格之前不能关闭(使用X)表格。我应该在哪个表单事件中写入控制代码
?
谢谢,
-Delen
I need to make sure that the user cannot close (using "X") the form before
saving the data on it. Which form event should I write the control code in?
Thank you,
-Delen
Durson,
在我看来,只有两种选择可以阻止你,一个
用户责备你,你的程序有一个bug,当他推动X和
没有任何反应。
这是在结束活动中捕获它而不是用消息框询问
关闭与否,而不是设置e.cancel。
或者迈克的这个很好的解决方案,因为那时候没有X我的
意见很多更好。
http://www.gotdotnet.com/Community/M...&Page=1#248801
我希望这有帮助,
Cor
Durson,
There are in my opinion only two kind of options which do prevent you that a
user blames you that your program has a bug when he pushes the X and
nothing happens.
That is catching it in the closing event and than ask with a messagebox to
close or not and than set the e.cancel.
Or this nice solution from Mike, because then there is no X what in my
opinion is much nicer.
http://www.gotdotnet.com/Community/M...&Page=1#248801
I hope this helps,
Cor
" Dursun" <都**** @ discussions.microsoft.com> schrieb:
"Dursun" <Du****@discussions.microsoft.com> schrieb:
我需要确保用户在保存表格之前不能关闭(使用X)表格。我应该在哪个表单事件中编写控件代码?
I need to make sure that the user cannot close (using "X") the form before
saving the data on it. Which form event should I write the control code
in?
\\\
Imports System.ComponentModel
..
..
..
Private Sub Form1_Closing(_
ByVal sender As Object,_
ByVal e As CancelEventArgs _
)处理MyBase.Closing
如果_
MsgBox(_
真的关闭?,_
MsgBoxStyle.YesNo或MsgBoxStyle.Question _
)= MsgBoxResult.No _
然后
e.Cancel = True
结束如果
结束子
///
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps .org />
VB< URL:http://classicvb.org/petition/>
\\\
Imports System.ComponentModel
..
..
..
Private Sub Form1_Closing( _
ByVal sender As Object, _
ByVal e As CancelEventArgs _
) Handles MyBase.Closing
If _
MsgBox( _
"Really close?", _
MsgBoxStyle.YesNo Or MsgBoxStyle.Question _
) = MsgBoxResult.No _
Then
e.Cancel = True
End If
End Sub
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
这篇关于如何在关闭之前捕获未保存的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!