我有一个用户表单,xForm,正在类模块中实例化(假设测试类) as:
'TestClass
Dim Form as New xForm
Private WithEvents EvForm as MSForms.UserForm
Set EvForm = Form
在 xForm 本身的类模块中,我有一些必须在表单关闭时执行的代码,仅当表单实际关闭时:
'xForm class module
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'Do some cleanup, otherwise the app would hang
'If not closing, don't cleanup anything, otherwise the app would hang
End Sub
QueryClose 事件也在 TestClass 中处理,并且可以避免表单关闭:
'TestClass
Private Sub EvForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'Verify if closing is allowed based on User Control values
Cancel = Not ClosingIsAllowed '<-- Pseudocode on the right side of "="
End Sub
如何测试在 xForm 类模块中的 TestClass 中设置的 Cancel = True?
让我们重新表述一下:如果 TestClass 中的 Cancel 设置为 True,则我不能在 xForm 类模块中执行清理代码。我怎样才能做到这一点?
到目前为止,我一直在考虑在 xForm 类中实现另一个事件(My_QueryClose?)并在 QueryClose 事件上引发它。在代码隐藏表单之外,我将只处理 My_QueryClose 事件,因此可以完全控制正在发生的事情。这是一种可行/更好的方法吗?