用于用户控件的VB6 Initialize事件称为AFTER Terminate事件

时间:2021-09-17 16:34:06

I have created a simple form in VB6, and added a simple, blank user control. The only code are Debug.Print statements in all major events.

我在VB6中创建了一个简单的表单,并添加了一个简单的空白用户控件。唯一的代码是所有重大事件中的Debug.Print语句。

For some reason, when the form is closed, the order of events in the User Control are:

出于某种原因,当表单关闭时,用户控件中的事件顺序为:

Terminate
Initialize
Read Properties
Resize

Why is this happening? Why are Initialize, ReadProperties and Resize called after Terminate? I could not find any evidence of this in Microsoft documentation.

为什么会这样?为何在终止后调用Initialize,ReadProperties和Resize?我在Microsoft文档中找不到任何此类证据。

EDIT:

Here is the code.

这是代码。

User control:

VERSION 5.00
Begin VB.UserControl UserControl1 
   ClientHeight    =   3600
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   4800
   ScaleHeight     =   3600
   ScaleWidth      =   4800
End
Attribute VB_Name = "UserControl1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private Sub UserControl_Initialize()
    Debug.Print "Initialize"
End Sub

Private Sub UserControl_InitProperties()
    Debug.Print "InitProperties"
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    Debug.Print "ReadProperties"
End Sub

Private Sub UserControl_Resize()
    Debug.Print "Resize"
End Sub

Private Sub UserControl_Show()
    Debug.Print "Show"
End Sub

Private Sub UserControl_Terminate()
    Debug.Print "Terminate"
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Debug.Print "WriteProperties"
End Sub

Form:

VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3030
   ClientLeft      =   120
   ClientTop       =   450
   ClientWidth     =   4560
   LinkTopic       =   "Form1"
   ScaleHeight     =   3030
   ScaleWidth      =   4560
   StartUpPosition =   3  'Windows Default
   Begin Project1.UserControl1 UserControl1 
      Height          =   2535
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   4095
      _extentx        =   7223
      _extenty        =   4471
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

1 个解决方案

#1


Debug.Print means your running this in debug mode in the IDE.

Debug.Print意味着您在IDE中以调试模式运行它。

When debugging you would see a Terminate when the form unloads, you then see the reinitialisation of the User Control as its re-loaded in the Form in the Form Designer for editing.

在调试时,您会在表单卸载时看到Terminate,然后您可以看到重新初始化用户控件,因为它在表单设计器的表单中重新加载以进行编辑。

This won't happen from a compiled EXE, you can replace Debug.Print with MsgBox to verify this.

这不会从已编译的EXE中发生,您可以用MsgBox替换Debug.Print来验证这一点。

#1


Debug.Print means your running this in debug mode in the IDE.

Debug.Print意味着您在IDE中以调试模式运行它。

When debugging you would see a Terminate when the form unloads, you then see the reinitialisation of the User Control as its re-loaded in the Form in the Form Designer for editing.

在调试时,您会在表单卸载时看到Terminate,然后您可以看到重新初始化用户控件,因为它在表单设计器的表单中重新加载以进行编辑。

This won't happen from a compiled EXE, you can replace Debug.Print with MsgBox to verify this.

这不会从已编译的EXE中发生,您可以用MsgBox替换Debug.Print来验证这一点。