• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1007
  • Last Modified:

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
0
BlueSky007
Asked:
BlueSky007
  • 4
  • 4
1 Solution
 
DeAnCommented:
'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?
0
 
DeAnCommented:
this will set the font the same as the form or container it's placed on, like the Label control does.
0
 
DeAnCommented:
oh, you need this too

Public Property Get Font() As Font
  Set Font = UserControl.Font
End Property

Public Property Set Font(ByVal New_Font As Font)
  Set UserControl.Font = New_Font
  PropertyChanged "Font"
End Property
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BlueSky007Author Commented:
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!
0
 
BlueSky007Author Commented:
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 !
0
 
BlueSky007Author Commented:
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
0
 
BlueSky007Author Commented:
Thank anyway for for idea!
0
 
DeAnCommented:
thanx BlueSky007, glad it helped ;)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now