VB6中的表单关闭事件?

Von*_*nes 2 vb6

只是想问,VB6 中是否有等效的 form_ opening 事件?(.bas)。我问的原因是,如果有打开的子窗口,我想防止首先关闭应用程序。

像这样的东西。

Private Sub MainForm_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

  If hasSubWindow Then
    MessageBox.Show("You currently have active sub-window(s)")
    e.Cancel = false
  End If

End Sub

Run Code Online (Sandbox Code Playgroud)

egl*_*ase 5

共有三个事件:Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)Form_Unload(Cancel As Integer)Form_Terminate()

Form_QueryUnloadForm_Unload在where 设置为 0 以外的任何值之前触发Cancel,取消卸载并UnloadMode指示卸载事件的原因。

请参阅https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-basic-6/aa445536(v=vs.60)?redirectedfrom=MSDN

Form_Unload接受一个整数,如果设置为 0 以外的任何值,则取消卸载。

Unload 事件过程是程序员通常放置清理代码的地方。Unload 事件在 QueryUnload 事件之后触发。Unload 事件过程采用单个参数,即 Cancel 参数。Unload 的 Cancel 参数的工作方式与 QueryUnload 的 Cancel 参数相同。

当表单的实例完全卸载并且所有表单的变量都已设置为 Nothing 时,Terminate 事件就会发生。仅当您在 Unload 事件过程期间或之后在代码中将表单显式设置为 Nothing 时,Terminate 事件才会发生。

来源: https ://www.freetutes.com/learn-vb6-advanced/lesson6/p5.html

就您而言,您可能希望将代码放入Form_QueryUnloadForm_Unload检查是否有任何其他打开的表单。

Private Sub Form_Unload(Cancel As Integer)
    If hasSubWindow = True Then
         MsgBox "You currently have active sub-window(s)", vbInformation, "Confirm"
        Cancel = 1
    End if
End Sub
Run Code Online (Sandbox Code Playgroud)