VB6 为用户控件初始化名为 AFTER Terminate 事件的事件
VB6 Initialize event called AFTER Terminate event for user controls
我在 VB6 中创建了一个简单的窗体,并添加了一个简单的空白用户控件。所有重大事件中唯一的代码是 Debug.Print 语句。
出于某种原因,当表单关闭时,用户控件中的事件顺序为:
Terminate
Initialize
Read Properties
Resize
为什么会这样?为什么在 Terminate 之后调用 Initialize、ReadProperties 和 Resize?我在 Microsoft 文档中找不到这方面的任何证据。
编辑:
这是代码。
用户控制:
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
表格:
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
Debug.Print
表示您的 运行 在 IDE.
中处于调试模式
调试时您会看到 Terminate
当表单卸载时,您会在 Form Designer[=21] 的表单中看到用户控件重新加载时的重新初始化=] 进行编辑。
编译后的 EXE 不会发生这种情况,您可以将 Debug.Print
替换为 MsgBox
以验证这一点。
我在 VB6 中创建了一个简单的窗体,并添加了一个简单的空白用户控件。所有重大事件中唯一的代码是 Debug.Print 语句。
出于某种原因,当表单关闭时,用户控件中的事件顺序为:
Terminate
Initialize
Read Properties
Resize
为什么会这样?为什么在 Terminate 之后调用 Initialize、ReadProperties 和 Resize?我在 Microsoft 文档中找不到这方面的任何证据。
编辑:
这是代码。
用户控制:
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
表格:
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
Debug.Print
表示您的 运行 在 IDE.
调试时您会看到 Terminate
当表单卸载时,您会在 Form Designer[=21] 的表单中看到用户控件重新加载时的重新初始化=] 进行编辑。
编译后的 EXE 不会发生这种情况,您可以将 Debug.Print
替换为 MsgBox
以验证这一点。