Mike Williams
2011-08-17 19:06:54 UTC
I have been attempting to create a User Control in which I can expose a font
object to use for various things in the Control and I've been following the
procedure outlined at the following MSDN page:
http://msdn.microsoft.com/en-us/library/aa261313(v=vs.60).aspx
The code works in that if you drop such a User Control on a Form and select
it you can see the Font in its Properties and you can set it fine, with the
User Control immediately displaying the newly selected font. However, when
you then run the program the font on the User Control reverts to its default
setting. It is still possible to set its various font properties at runtime
in code, but I really would like it to use the font that was set by the user
at design time in the same way that other controls do. I'm obviously doing
something wrong and I wonder if anyone knows how to solve this problem?
The code in my User Control is as shown below.
Mike
Option Explicit
Private WithEvents mFont As StdFont
Private Sub UserControl_Initialize()
Set mFont = New StdFont
Set UserControl.Font = mFont
End Sub
Public Property Get Font() As StdFont
Set Font = mFont
End Property
Public Property Set Font(mnewFont As StdFont)
With mFont
.Bold = mnewFont.Bold
.Italic = mnewFont.Italic
.Name = mnewFont.Name
.Size = mnewFont.Size
End With
PropertyChanged "Font"
End Property
Private Sub mFont_FontChanged(ByVal PropertyName As String)
Set UserControl.Font = mFont
Refresh
End Sub
Private Sub UserControl_Paint()
Cls
Print "Hello"
End Sub
object to use for various things in the Control and I've been following the
procedure outlined at the following MSDN page:
http://msdn.microsoft.com/en-us/library/aa261313(v=vs.60).aspx
The code works in that if you drop such a User Control on a Form and select
it you can see the Font in its Properties and you can set it fine, with the
User Control immediately displaying the newly selected font. However, when
you then run the program the font on the User Control reverts to its default
setting. It is still possible to set its various font properties at runtime
in code, but I really would like it to use the font that was set by the user
at design time in the same way that other controls do. I'm obviously doing
something wrong and I wonder if anyone knows how to solve this problem?
The code in my User Control is as shown below.
Mike
Option Explicit
Private WithEvents mFont As StdFont
Private Sub UserControl_Initialize()
Set mFont = New StdFont
Set UserControl.Font = mFont
End Sub
Public Property Get Font() As StdFont
Set Font = mFont
End Property
Public Property Set Font(mnewFont As StdFont)
With mFont
.Bold = mnewFont.Bold
.Italic = mnewFont.Italic
.Name = mnewFont.Name
.Size = mnewFont.Size
End With
PropertyChanged "Font"
End Property
Private Sub mFont_FontChanged(ByVal PropertyName As String)
Set UserControl.Font = mFont
Refresh
End Sub
Private Sub UserControl_Paint()
Cls
Print "Hello"
End Sub