我在VB6中创建了一个简单的表单,并添加了一个简单的空白用户控件。唯一的代码是所有重大事件中的Debug.Print语句。
出于某种原因,当表单关闭时,用户控件中的事件顺序为:
Terminate
Initialize
Read Properties
Resize
为什么会这样?为何在终止后调用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
答案 0 :(得分:5)
Debug.Print
表示您在IDE中以调试模式运行它。
在调试时,您会在表单卸载时看到Terminate
,然后您会看到重新初始化用户控件,因为它已重新加载到表单设计器中的表单中进行编辑。
这不会从已编译的EXE中发生,您可以将Debug.Print
替换为MsgBox
来验证这一点。