Private Sub UserControl_WriteProperties(PropBag As PropertyBag) PropBag.WriteProperty "ColACaption", LstVw.ColumnHeaders.Item(1).Text PropBag.WriteProperty "ColBCaption", LstVw.ColumnHeaders.Item(2).Text PropBag.WriteProperty "ColAWidth", LstVw.ColumnHeaders.Item(1).Width PropBag.WriteProperty "ColBWidth", LstVw.ColumnHeaders.Item(2).Width PropBag.WriteProperty "LstVwHeight", LstVw.Height PropBag.WriteProperty "LstVwWight", LstVw.Width End SubPrivate Sub UserControl_ReadProperties(PropBag As PropertyBag) LstVw.ColumnHeaders.Item(1).Text = PropBag.ReadProperty("ColACaption", "±àºÅ") LstVw.ColumnHeaders.Item(2).Text = PropBag.ReadProperty("ColBCaption", "Ãû³Æ") LstVw.ColumnHeaders.Item(1).Width = PropBag.ReadProperty("ColAWidth", 1100) LstVw.ColumnHeaders.Item(2).Width = PropBag.ReadProperty("ColBWidth", 1440) LstVw.Height = PropBag.ReadProperty("LstVwHeight", 1935) LstVw.Width = PropBag.ReadProperty("LstVwWight", 2595) End Sub
cuiyxy(沧海鲨鱼) 使用ListView确实也是一个好办法!
*********************** usercontrol部分: 还没写完. *********************** Option Explicit 'Property Variables: Dim m_Employees As Persons 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES! 'MemberInfo=9,0,0,0 Public Property Get Employees() As Persons Set Employees = m_Employees End PropertyPublic Property Set Employees(ByVal New_Employees As Person) Set m_Employees = New_Employees PropertyChanged "Employees" End PropertyPrivate Sub UserControl_Initialize() Set m_Employees = New Persons End Sub'Load property values from storage Private Sub UserControl_ReadProperties(PropBag As PropertyBag) Dim i As Long Dim PersonName As String Dim sex As Boolean Dim age As Long i = PropBag.ReadProperty("EmployeesNumbers", 0) While i > 0 PersonName = PropBag.ReadProperty("Employees" & i & "name", "fling_boy") sex = PropBag.ReadProperty("Employees" & i & "sex", True) age = PropBag.ReadProperty("Employees" & i & "age", 24)
Call m_Employees.Add(PersonName, age, sex)
i = i - 1 Wend End SubPrivate Sub UserControl_Terminate() Set m_Employees = Nothing End Sub'Write property values to storage Private Sub UserControl_WriteProperties(PropBag As PropertyBag) Dim i As Long For i = 0 To m_Employees.Count - 1 Call PropBag.WriteProperty("Employees" & i & "name", m_Employees(i).PersonName, "fling_boy") Call PropBag.WriteProperty("Employees" & i & "sex", m_Employees(i).sex, True) Call PropBag.WriteProperty("Employees" & i & "age", m_Employees(i).age, 24) Next Call PropBag.WriteProperty("EmployeesNumbers", m_Employees.Count, 0) End Sub
************** person class ************** Option Explicit'local variable(s) to hold property value(s) Private mvarPersonName As String 'local copy Private mvarage As Long 'local copy Private mvarsex As Boolean 'local copy Public Property Let sex(ByVal vData As Boolean) 'used when assigning a value to the property, on the left side of an assignment. 'Syntax: X.sex = 5 mvarsex = vData End Property Public Property Get sex() As Boolean 'used when retrieving value of a property, on the right side of an assignment. 'Syntax: Debug.Print X.sex sex = mvarsex End PropertyPublic Property Let age(ByVal vData As Long) 'used when assigning a value to the property, on the left side of an assignment. 'Syntax: X.age = 5 mvarage = vData End Property Public Property Get age() As Long 'used when retrieving value of a property, on the right side of an assignment. 'Syntax: Debug.Print X.age age = mvarage End PropertyPublic Property Let PersonName(ByVal vData As String) 'used when assigning a value to the property, on the left side of an assignment. 'Syntax: X.PersonName = 5 mvarPersonName = vData End Property Public Property Get PersonName() As String 'used when retrieving value of a property, on the right side of an assignment. 'Syntax: Debug.Print X.PersonName PersonName = mvarPersonName End Property
***************** persons col ***************** Option Explicit'local variable to hold collection Private mCol As CollectionPublic Function Add(PersonName As String, age As Long, sex As Boolean, Optional sKey As String) As Person 'create a new object Dim objNewMember As Person Set objNewMember = New Person 'set the properties passed into the method objNewMember.PersonName = PersonName objNewMember.age = age objNewMember.sex = sex If Len(sKey) = 0 Then mCol.Add objNewMember Else mCol.Add objNewMember, sKey End If 'return the object created Set Add = objNewMember Set objNewMember = Nothing End FunctionPublic Property Get Item(vntIndexKey As Variant) As Person 'used when referencing an element in the collection 'vntIndexKey contains either the Index or Key to the collection, 'this is why it is declared as a Variant 'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5) Set Item = mCol(vntIndexKey) End PropertyPublic Property Get Count() As Long 'used when retrieving the number of elements in the 'collection. Syntax: Debug.Print x.Count Count = mCol.Count End Property Public Sub Remove(vntIndexKey As Variant) 'used when removing an element from the collection 'vntIndexKey contains either the Index or Key, which is why 'it is declared as a Variant 'Syntax: x.Remove(xyz) mCol.Remove vntIndexKey End Sub Public Property Get NewEnum() As IUnknown 'this property allows you to enumerate 'this collection with the For...Each syntax Set NewEnum = mCol.[_NewEnum] End Property Private Sub Class_Initialize() 'creates the collection when this class is created Set mCol = New Collection End Sub Private Sub Class_Terminate() 'destroys collection when this class is terminated Set mCol = Nothing End Sub****************** 没有写完,我现在没时间了. 如果你懂了,我就不写了,如不懂等我有时间再给你写完整.
PropBag.WriteProperty "ColACaption", LstVw.ColumnHeaders.Item(1).Text
PropBag.WriteProperty "ColBCaption", LstVw.ColumnHeaders.Item(2).Text
PropBag.WriteProperty "ColAWidth", LstVw.ColumnHeaders.Item(1).Width
PropBag.WriteProperty "ColBWidth", LstVw.ColumnHeaders.Item(2).Width
PropBag.WriteProperty "LstVwHeight", LstVw.Height
PropBag.WriteProperty "LstVwWight", LstVw.Width
End SubPrivate Sub UserControl_ReadProperties(PropBag As PropertyBag)
LstVw.ColumnHeaders.Item(1).Text = PropBag.ReadProperty("ColACaption", "񅧏")
LstVw.ColumnHeaders.Item(2).Text = PropBag.ReadProperty("ColBCaption", "Ãû³Æ")
LstVw.ColumnHeaders.Item(1).Width = PropBag.ReadProperty("ColAWidth", 1100)
LstVw.ColumnHeaders.Item(2).Width = PropBag.ReadProperty("ColBWidth", 1440)
LstVw.Height = PropBag.ReadProperty("LstVwHeight", 1935)
LstVw.Width = PropBag.ReadProperty("LstVwWight", 2595)
End Sub
usercontrol部分:
还没写完.
***********************
Option Explicit
'Property Variables:
Dim m_Employees As Persons
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=9,0,0,0
Public Property Get Employees() As Persons
Set Employees = m_Employees
End PropertyPublic Property Set Employees(ByVal New_Employees As Person)
Set m_Employees = New_Employees
PropertyChanged "Employees"
End PropertyPrivate Sub UserControl_Initialize()
Set m_Employees = New Persons
End Sub'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Dim i As Long
Dim PersonName As String
Dim sex As Boolean
Dim age As Long i = PropBag.ReadProperty("EmployeesNumbers", 0)
While i > 0
PersonName = PropBag.ReadProperty("Employees" & i & "name", "fling_boy")
sex = PropBag.ReadProperty("Employees" & i & "sex", True)
age = PropBag.ReadProperty("Employees" & i & "age", 24)
Call m_Employees.Add(PersonName, age, sex)
i = i - 1
Wend
End SubPrivate Sub UserControl_Terminate()
Set m_Employees = Nothing
End Sub'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Dim i As Long
For i = 0 To m_Employees.Count - 1
Call PropBag.WriteProperty("Employees" & i & "name", m_Employees(i).PersonName, "fling_boy")
Call PropBag.WriteProperty("Employees" & i & "sex", m_Employees(i).sex, True)
Call PropBag.WriteProperty("Employees" & i & "age", m_Employees(i).age, 24)
Next
Call PropBag.WriteProperty("EmployeesNumbers", m_Employees.Count, 0)
End Sub
person class
**************
Option Explicit'local variable(s) to hold property value(s)
Private mvarPersonName As String 'local copy
Private mvarage As Long 'local copy
Private mvarsex As Boolean 'local copy
Public Property Let sex(ByVal vData As Boolean)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.sex = 5
mvarsex = vData
End Property
Public Property Get sex() As Boolean
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.sex
sex = mvarsex
End PropertyPublic Property Let age(ByVal vData As Long)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.age = 5
mvarage = vData
End Property
Public Property Get age() As Long
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.age
age = mvarage
End PropertyPublic Property Let PersonName(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.PersonName = 5
mvarPersonName = vData
End Property
Public Property Get PersonName() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.PersonName
PersonName = mvarPersonName
End Property
persons col
*****************
Option Explicit'local variable to hold collection
Private mCol As CollectionPublic Function Add(PersonName As String, age As Long, sex As Boolean, Optional sKey As String) As Person
'create a new object
Dim objNewMember As Person
Set objNewMember = New Person
'set the properties passed into the method
objNewMember.PersonName = PersonName
objNewMember.age = age
objNewMember.sex = sex
If Len(sKey) = 0 Then
mCol.Add objNewMember
Else
mCol.Add objNewMember, sKey
End If
'return the object created
Set Add = objNewMember
Set objNewMember = Nothing
End FunctionPublic Property Get Item(vntIndexKey As Variant) As Person
'used when referencing an element in the collection
'vntIndexKey contains either the Index or Key to the collection,
'this is why it is declared as a Variant
'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
Set Item = mCol(vntIndexKey)
End PropertyPublic Property Get Count() As Long
'used when retrieving the number of elements in the
'collection. Syntax: Debug.Print x.Count
Count = mCol.Count
End Property
Public Sub Remove(vntIndexKey As Variant)
'used when removing an element from the collection
'vntIndexKey contains either the Index or Key, which is why
'it is declared as a Variant
'Syntax: x.Remove(xyz)
mCol.Remove vntIndexKey
End Sub
Public Property Get NewEnum() As IUnknown
'this property allows you to enumerate
'this collection with the For...Each syntax
Set NewEnum = mCol.[_NewEnum]
End Property
Private Sub Class_Initialize()
'creates the collection when this class is created
Set mCol = New Collection
End Sub
Private Sub Class_Terminate()
'destroys collection when this class is terminated
Set mCol = Nothing
End Sub******************
没有写完,我现在没时间了.
如果你懂了,我就不写了,如不懂等我有时间再给你写完整.