注意 :这可能是在黑暗中拍摄的,纯粹是出于好奇,我正在问。
当使用Microsoft公共控制库(mscomctl.ocx)中的ImageList控件时,我发现VB6生成的FRM代码无法解析为不动产/方法名称,我很好奇如何制作分辨率。下面给出了生成的FRM代码的示例,其中包含3个图像的ImageList:
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标记通常表示正在分配复合属性(对象),例如大多数控件的Font对象,例如:
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。< Property Name>。
使用ImageList,没有名为Images的属性。与属性Images相关联的GUID指示实现接口IImages的类型ListImages。这种类型是有意义的,因为ImageList控件具有名为ListImages的属性,其类型为IImages。其次,类型IImages上不存在属性ListImage1,ListImage2和ListImage3,但与这些属性关联的GUID指示实现接口IImage的类型ListImage。这种类型也很有意义,因为IImages实际上是IImage的集合。
对我来说没有意义的是VB6如何建立这些关联。 VB6如何知道如何建立名称Images - >之间的关联。 ListImages纯粹是因为关联类型(由GUID提供) - 也许是因为它是该类型的唯一属性?其次,它如何将ListImage1,ListImage2和ListImage3解析为集合IImages的附加组件,它是否使用Add方法?或者可能是ControlDefault属性?
也许VB6具有这种控制的特定知识,并且不存在逻辑分辨率?
答案 0 :(得分:2)
你可以看到这个相当人为的例子正在发生什么。从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作为保存。您可能想为Sub Main添加Module1
' 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
在其rs
重载中作为属性WriteProperty
保留。 Class1
确定其m_sText
成员变量(或Text
公共属性)作为txt
成员在frm传递的IPropertyBag
中保留。没有什么需要公共属性名称来匹配内部属性包名称。我个人会使用短路ID来减少膨胀(如果可能的话,最好使用VB6)。
答案 1 :(得分:0)
我猜测GUID({2C247F25-8591-11D1-B16A-00C0F0283628})指向关联的ImageList控件,ListImage1,ListImage2等等......就在那里枚举所有图像。
这有点像WPF关联控件的早期版本(例如,TextBox可以引用其封闭网格进行放置)。