Link to home
Start Free TrialLog in
Avatar of BlueSky007
BlueSky007

asked on

Create a Font Property to a new UserControl

I want to create my own Label Control (like the Label form Form 2.0) and I can't create the Font Property.
After I define the Property FONT, in the Properties Window the Font Property appears, but when I select a Font or a Size, the VB tells me "Invalid property value", and i don't know how to work with FONT Object!!! (i didn't used before)

 The code that i used:

Dim m_BorderColor As OLE_COLOR
Dim m_BorderVisible As Boolean
Dim m_BackColor As OLE_COLOR
Dim m_ForeColor As OLE_COLOR
Dim m_Caption As String

.....................

'----- some other properties
Public Property Get Caption() As String
    Caption = m_Caption
End Property

Public Property Let Caption(ByVal New_Caption As String)
    m_Caption = New_Caption
    PropertyChanged "Caption"
    sDrawLabel
End Property
'---------

'- the font property
Public Property Get Font() As StdFont '(i've tried with                                    IFontDisp and nothing)

'? -> i don't know what to put here!
End Property

Public Property Let Font(ByVal New_Font As StdFont)
'?
End Property
Avatar of DeAn
DeAn

'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
  Set UserControl.Font = Ambient.Font
End Sub

'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  Set UserControl.Font = PropBag.ReadProperty("Font", Ambient.Font)
End Sub

'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  Call PropBag.WriteProperty("Font", UserControl.Font, Ambient.Font)
End Sub

is this any help?
this will set the font the same as the form or container it's placed on, like the Label control does.
ASKER CERTIFIED SOLUTION
Avatar of DeAn
DeAn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BlueSky007

ASKER

I've tried this code but it said that FONT (in tne Set Font = UserControl.Font): Sub or Function not found!

The Font object is valit, becouse if i type Font. , after DOT appers the properties!

What is the problem? Thanks!
I create a new UserControl with a simple Lable in control and i put the code that you give me, but same error ... Sub or Function not found, in the UserControl_initProperties at Font from Set UserControl.Font = ....

I don't know where is the problem. You've tried this code or you have a sample that works (made be you of course)?

Thanks !
I've tried this code and it works (I don't know how i've done it, but it works fine)

'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
    Set Label1.Font = Ambient.Font
    'Print "Adsfoqwjef"
End Sub

Public Property Get Font() As StdFont
 Set Font = Label1.Font
End Property
Public Property Set Font(ByVal New_Font As StdFont)
 Set Label1.Font = New_Font
 'Print "Adsfoqwjef"
 'PropertyChanged "Font"
End Property

'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
 Label1.Font = PropBag.ReadProperty("Font", Ambient.Font)
End Sub

'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    PropBag.WriteProperty "Font", Label1.Font, Ambient.Font
End Sub

Firs i've tried with UserControl instead the Label1 and work with that too, thank
Thank anyway for for idea!
thanx BlueSky007, glad it helped ;)