mikerickson
10-17-2011, 03:06 PM
I am using Class modules to make a custom object, for use in a userform.
This object has many Labels, all with the same properties.
My object has properties like BackColor and the Property Let routines apply the input values to all the labels. So that code like this gets the expected results
'in UserForm module
Dim myObject as New Class1
' ...
myObject.BackColor = RGB(100,200,100)
'in Class module
Dim myColor as OLE_Color
Property Let BackColor(newColor As OLE_Color)
myColor = newColor
Label1.BackColor = myColor
Label2.BackColor = myColor
' etc.
End PropertyThis works well, until I come to the Font property.
My objective is that a line in the userform module
'in uf module
LineAlpha:
myObject.Font.Size = 12 will set the font size of all the labels to 12.
The problem is how to do that.
I can define a property
'in class module
Dim myFont as NewFont
Property Get Font() as NewFont
Set Font = myFont
End Property
Property Set Font(aFont as NewFont)
Set myFont = aFont
Label1.Font.Size = myFont.Size
Label2.Font.Size = myFont.Size
Label1.Font.Bold = myFont.Bold
' etc.
End Property
The problem with that approach is that LineAlpha calls the Property Get code, not the Property Set.
I could write a custom MyFont object with properties like Bold, Charset, etc. and Class1's Font property would return a MyFont object.
In that case, LineAlpha would call a Property Get routine from Class1 and a Property Let routine from MyFont.
The Property Let routines in MyFont could raise an event that would get the values into the labels.
Or am I missing something, is there another way that LineAlpha could trigger the passing of Size=12 down to the lables without creating a MyFont class?
This object has many Labels, all with the same properties.
My object has properties like BackColor and the Property Let routines apply the input values to all the labels. So that code like this gets the expected results
'in UserForm module
Dim myObject as New Class1
' ...
myObject.BackColor = RGB(100,200,100)
'in Class module
Dim myColor as OLE_Color
Property Let BackColor(newColor As OLE_Color)
myColor = newColor
Label1.BackColor = myColor
Label2.BackColor = myColor
' etc.
End PropertyThis works well, until I come to the Font property.
My objective is that a line in the userform module
'in uf module
LineAlpha:
myObject.Font.Size = 12 will set the font size of all the labels to 12.
The problem is how to do that.
I can define a property
'in class module
Dim myFont as NewFont
Property Get Font() as NewFont
Set Font = myFont
End Property
Property Set Font(aFont as NewFont)
Set myFont = aFont
Label1.Font.Size = myFont.Size
Label2.Font.Size = myFont.Size
Label1.Font.Bold = myFont.Bold
' etc.
End Property
The problem with that approach is that LineAlpha calls the Property Get code, not the Property Set.
I could write a custom MyFont object with properties like Bold, Charset, etc. and Class1's Font property would return a MyFont object.
In that case, LineAlpha would call a Property Get routine from Class1 and a Property Let routine from MyFont.
The Property Let routines in MyFont could raise an event that would get the values into the labels.
Or am I missing something, is there another way that LineAlpha could trigger the passing of Size=12 down to the lables without creating a MyFont class?