VB6 ImageList Frm代码生成
注意:这可能是在黑暗中拍摄的,我问的纯粹是出于好奇 当使用Microsoft Common control lib(mscomctl.ocx)中的ImageList控件时,我发现VB6生成的FRM代码不能解析为不动产/方法名称,我很好奇如何进行解析。生成的FRM代码示例如下所示,其中ImageList包含3个图像:VB6 ImageList Frm代码生成,vb6,imagelist,Vb6,Imagelist,注意:这可能是在黑暗中拍摄的,我问的纯粹是出于好奇 当使用Microsoft Common control lib(mscomctl.ocx)中的ImageList控件时,我发现VB6生成的FRM代码不能解析为不动产/方法名称,我很好奇如何进行解析。生成的FRM代码示例如下所示,其中ImageList包含3个图像: Begin MSComctlLib.ImageList ImageList1 BackColor = -2147483643 Imag
Begin MSComctlLib.ImageList ImageList1
BackColor = -2147483643
ImageWidth = 100
ImageHeight = 45
MaskColor = 12632256
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 3
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form1.frx":0054
Key = ""
EndProperty
BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form1.frx":3562
Key = ""
EndProperty
BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form1.frx":6A70
Key = ""
EndProperty
EndProperty
End
根据我的经验,BeginProperty标记通常意味着要为其指定复合属性(对象),例如大多数控件的字体对象,例如:
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 10950
ClientLeft = 60
ClientTop = 450
ClientWidth = 7215
BeginProperty Font
Name = "MS Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = -1 'True
Strikethrough = 0 'False
EndProperty
End
可以很容易地将其解析为VB.Form.Font
对于ImageList,没有称为Images的属性。与属性映像关联的GUID指示实现接口IImages的类型ListImages。这种类型是有意义的,因为ImageList控件有一个名为ListImages的属性,它属于IImages类型。其次,类型IImage上不存在属性ListImage1、ListImage2和ListImage3,但与这些属性关联的GUID指示实现接口IImage的类型ListImage。这种类型也有意义,因为IImages实际上是IImage的集合
对我来说没有意义的是VB6如何建立这些关联。VB6如何知道在名称Images->ListImages之间建立关联纯粹是因为关联的类型(由GUID提供)——可能是因为它是该类型的唯一属性?其次,它如何将ListImage1、ListImage2和ListImage3解析为集合IImages的附加项,以及它是否使用Add方法?或者是ControlDefault属性
可能VB6对该控件有特定的了解,并且不存在逻辑解析?我猜GUID({2C247F25-8591-11D1-B16A-00C0F0283628})指向关联的ImageList控件和ListImage1、ListImage2等。。。只是为了列举所有的图像
这有点像WPF相关控件的早期版本(例如,文本框可以引用其封闭网格进行放置)。您可以看到这个相当做作的示例中发生了什么。从ActiveX项目开始,添加
Class1
,并将其标记为Persistable=1
' Class1
Option Explicit
Private m_sText As String
Property Get Text() As String
Text = m_sText
End Property
Property Let Text(sValue As String)
m_sText = sValue
End Property
Private Sub Class_ReadProperties(PropBag As PropertyBag)
With PropBag
m_sText = .ReadProperty("txt", "")
End With
End Sub
Private Sub Class_WriteProperties(PropBag As PropertyBag)
With PropBag
.WriteProperty "txt", m_sText, ""
End With
End Sub
添加UserControl1
' UserControl1
Option Explicit
Private m_oData As Class1
Property Get Data() As Class1
Set Data = m_oData
End Property
Private Sub UserControl_Initialize()
Set m_oData = New Class1
m_oData.Text = "this is a test"
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
With PropBag
Set m_oData = .ReadProperty("rs", Nothing)
End With
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
With PropBag
.WriteProperty "rs", m_oData, Nothing
End With
End Sub
添加Form1并在其上放置UserControl1作为save。您可能希望为Sub-Main添加模块1
' Module1
Sub Main()
With New Form1
.Show
End With
End Sub
这是我的Form1.frm
文件
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2400
ClientLeft = 48
ClientTop = 432
ClientWidth = 3744
LinkTopic = "Form1"
ScaleHeight = 2400
ScaleWidth = 3744
StartUpPosition = 3 'Windows Default
Begin Project1.UserControl1 UserControl11
Height = 516
Left = 924
TabIndex = 0
Top = 588
Width = 1020
_ExtentX = 1799
_ExtentY = 910
BeginProperty rs {326250A4-CA0D-4F88-8F20-DAA391CF8E79}
txt = "this is a test"
EndProperty
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
因此
UserControl1
确定对象m_oData
在其WriteProperty
重载中作为属性rs
持久化Class1
确定其m_sText
成员变量(或Text
public属性)作为txt
成员在IPropertyBag
frm传递中持久化。没有任何东西要求公共属性名称与内部属性包名称匹配。我个人会使用短ID来减少膨胀(如果可能的话,使用VB6)。+1。关于编写自己的控件,所有这些都记录在VB6手册中。它建议您“应在属性包中使用属性名称,因为它将出现在frm文本文件中,并且控件用户可能会看到”,但您不必这样做。同样的原则也适用于用其他编程语言编写的COM控件。