Results 1 to 3 of 3

Thread: Font property not fully working

  1. #1

    Thread Starter
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577

    Font property not fully working

    Hi

    I have added a Font property to my active x control so developers can change the font using vb's properties window

    To do this I have the following code..

    VB Code:
    1. Public Property Set Font(ByVal oFont As StdFont)
    2.     Debug.Print "1.Write Font Size: " & m_oFont.Size
    3.     With m_oFont
    4.         .Bold = oFont.Bold
    5.         .Charset = oFont.Charset
    6.         .Italic = oFont.Italic
    7.         .Name = oFont.Name
    8.         .Size = oFont.Size
    9.         .Strikethrough = oFont.Strikethrough
    10.         .Underline = oFont.Underline
    11.         .Weight = oFont.Weight
    12.     End With
    13.    
    14.     PropertyChanged "Font"
    15.    
    16.     Debug.Print "2.Write Font Size: " & m_oFont.Size
    17. End Property
    18. Public Property Get Font() As StdFont
    19.     Set Font = m_oFont
    20. End Property

    And here is my Property bag methods

    VB Code:
    1. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    2.     PropBag.WriteProperty "Font", m_oFont
    3. End Sub
    4.  
    5. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    6.     Debug.Print "1.Read Font Size: " & m_oFont.Size
    7.     m_oFont = PropBag.ReadProperty("Font")
    8.     Debug.Print "2.Read Font Size: " & m_oFont.Size
    9. End Sub

    now If i pop my control on my form and set a new font with the font dialog then click ok to confirm that font, the font is set to what i need.

    But when i click run, all the font property values are reset except Font.Name

    I dont understand why only the Font Name works, all the other attributes like bold, size, type etc reset to there default values.

    Does anyone know why this is doing this to me?


    Thanks

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    I think the problem is in the ReadProperties event. You are missing Set before m_oFont = PropBag... Since the Name property is the default for a Font object it is the only one being changed.

  3. #3

    Thread Starter
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577
    Originally posted by brucevde
    I think the problem is in the ReadProperties event. You are missing Set before m_oFont = PropBag... Since the Name property is the default for a Font object it is the only one being changed.
    Thank you, that was infact the solution. I've never used the Font object before so I didnt think about the set.

    Thanks again, i can finally continue with my control without getting annoyed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width