Results 1 to 18 of 18

Thread: [RESOLVED] UserControl with MSFlexGrid needs Font change

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    484

    Resolved [RESOLVED] UserControl with MSFlexGrid needs Font change

    I'm busy (trying!) to create a UserControl that uses a MSFlexGrid with a button or three for adding rows/cols and removing rows/cols at runtime. I've got most of the events and properties figured out (i hope!)

    My problem is I can't get the font figured out. How do I set the Font property of the MSFlexgrid in my UserControl? I don't want to change the Font of the buttons in the UserControl only the MSFlexGrid.

    I've got the Font property into the UserControl and can choose the Font for the UserControl at design time but can't get the MSFlexGrid to show the chosen Font. It reverts back to the font I used for the MSFlexGrid while designing the UserControl.

    Has done the following (the MSFlexGrid in the UserControl are named MSFG):

    In UserControl.WriteProperties
    Code:
    PropBag.WriteProperty "Font", Font, UserControl.Font
    In UserControl.ReadProperties
    Code:
    Set Font = PropBag.ReadProperty("Font", Ambient.Font)
    And the Property Get and Set functions
    Code:
    Public Property Get Font() As Font
         Set Font = UserControl.Font
    End Property
    
    Public Property Set Font(ByVal fntNewFont As Font)
         Set UserControl.Font = fntNewFont
         Set MSFG.Font = UserControl.Font
         UserControl.PropertyChanged "Font"
    End Property
    Any and all help appreciated. This is driving me nuts!

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: UserControl with MSFlexGrid needs Font change

    When you use WriteProperty and supply the optional default value, nothing is written if the value to be stored is same as the default property. Your .WriteProperty statement has no effect because you are writing Font which is your public Font property which is also the same as your default property of UserControl.Font. Simply remove that optional parameter.
    Last edited by LaVolpe; Mar 8th, 2011 at 05:27 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    484

    Re: UserControl with MSFlexGrid needs Font change

    Thanks LaVolpe.

    Just one minor problem. The MSFlexGrid in the UserControl defaults to a grid of 3x3. Attached is a screenshot of the grid with some data in it. Notice that the captions of columns A and B and rows 1 and 2 is not in the font as set for the FlexGrid/UserControl (in this case Tahoma Bold-Italic). The rest of the grid is in the correct font

    It has to do with the default grid size. If I change the default to 2x2 grid column A and row 1 is not set but the rest are.

    Any ideas?
    Attached Images Attached Images  

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: UserControl with MSFlexGrid needs Font change

    I haven't used the MSFlexGrid control in over a decade; so no longer familiar with it. Do you have VB service pack 6 loaded?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    484

    Re: UserControl with MSFlexGrid needs Font change

    Yes. SP6 installed plus other updates that were issued.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: UserControl with MSFlexGrid needs Font change

    Quote Originally Posted by Bezzie View Post
    ..It has to do with the default grid size. If I change the default to 2x2 grid column A and row 1 is not set but the rest are.

    Any ideas?
    Interesting. Have you tried to default it to 1x1 and then add them via code instead? In the properties window for that control, set the Fixed Rows/Cols values each to 0 and the Rows/Cols value each to 1. Then during your control's Initialize event, add this. I don't know if it will resolve the problem or not.
    Code:
        MSFlexGrid.Rows = 4
        MSFlexGrid.Cols = 4
        MSFlexGrid.FixedCols = 1
        MSFlexGrid.FixedRows = 1
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    484

    Re: UserControl with MSFlexGrid needs Font change

    Tried it but doesn't help. The number of cols and rows set in the Initialize event still does not show the correct font. Looks like the font gets set after the initialize event having the same effect as if it was set in the properties before.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    484

    Re: UserControl with MSFlexGrid needs Font change

    Would probably have to change the font cell by cell. In which event would one have to try that. It would have to be the first event that runs after the ReadProperties event.

    Is there a way to find out in which order the events are fired other than putting a Debug.Print statement in each event?

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: UserControl with MSFlexGrid needs Font change

    Here's a pdf document with just about everything you wanted to know about ActiveX controls/dlls. Chapter 17 is primarily ocx, but scan the table of contents for other chapters of interest.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    484

    Re: UserControl with MSFlexGrid needs Font change

    Eish! This is a thick PDF.

    Thanks LaVolpe, will read and re-read it.

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: UserControl with MSFlexGrid needs Font change

    Quote Originally Posted by Bezzie View Post
    ... It would have to be the first event that runs after the ReadProperties event.
    Keep this in mind and reading the ocx chapters in that link should help too.
    ReadProperites is NEVER called the very first time a usercontrol is placed on a form, InitProperites is called then. After that first time, InitProperties is never called again and ReadProperties is called thereafter. Initialize event is always called. I would expect when Initialize is called that the FlexGrid is already created.

    By the way, I could not replicate your problem by using the flex grid in a form, however, I may have time to give it a quick test tonight using code similar to yours to see if I can replicate the problem.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    484

    Re: UserControl with MSFlexGrid needs Font change

    I can post my code if it'll help. It's ugly but it's a try.

  13. #13
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: UserControl with MSFlexGrid needs Font change

    Here's what I've done. It works perfectly and doesn't exhibit the behavior you are describing.
    Code:
    Public Property Set Font(newFont As StdFont)
        Set MSFlexGrid1.Font = newFont
        PropertyChanged "Font"
    End Property
    Public Property Let Font(newFont As stdFont)
        Set Me.Font = newFont
    End Property
    Public Property Get Font() As StdFont
        Set Font = MSFlexGrid1.Font
    End Property
    
    Private Sub UserControl_Initialize()
    End Sub
    
    Private Sub UserControl_InitProperties()
        Set MSFlexGrid1.Font = Ambient.Font
    End Sub
    
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
        Set MSFlexGrid1.Font = PropBag.ReadProperty("Font", Ambient.Font)
    End Sub
    
    Private Sub UserControl_Show()
        ' should use a flag and set it after this is called
        ' if this gets called again and flag is set, then don't re-do the headers
        MSFlexGrid1.TextMatrix(0, 1) = "A"
        MSFlexGrid1.TextMatrix(0, 2) = "B"
        MSFlexGrid1.TextMatrix(0, 3) = "C"
        MSFlexGrid1.TextMatrix(1, 0) = "1"
        MSFlexGrid1.TextMatrix(2, 0) = "2"
        MSFlexGrid1.TextMatrix(3, 0) = "3"
    End Sub
    
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
        PropBag.WriteProperty "Font", MSFlexGrid1.Font, Ambient.Font
    End Sub
    Note that I don't mess with the UserControl.Font above. Simply because IMO not needed. The usercontrol.font probably should be a separate property if it is used differently than the flexgrid font. You can set the UC font if desired, regardless.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    484

    Re: UserControl with MSFlexGrid needs Font change

    I must be missing something somewhere. Mine still doesn't work as it should. I've attached the project. Not commented well and lots of rubbish still in there especially Debug.Print statements.

    Maybe you can see the error in the code.
    Attached Files Attached Files

  15. #15
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: UserControl with MSFlexGrid needs Font change

    I'll leave it to you to experiment and see if you can find the reason, but moving the following line from the bottom of ReadProperties to the top seems to solve the problem
    Code:
    Set MSFG.Font = PropBag.ReadProperty("Font", Ambient.Font)
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    484

    Re: UserControl with MSFlexGrid needs Font change

    Narrowed it down to the ClipAll function. When it's after the ClipAll ReadProperty it doesn't work but before the ClipAll ReadProperty it works but I can't see/think why?

  17. #17
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: UserControl with MSFlexGrid needs Font change

    I've narrowed it down a bit further.

    If you rem out your call to FixCaptions in your ClipAll function, problem does not appear
    Now, un-reming that and going into the FixCaptions function, rem-ing out setting font to Bold, then problem does not occur. Like I've said before, I'm no longer familiar with the flex grid and don't know what the workaround would be or why that call is affecting the display, but it appears to be. Enjoy
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Roodepoort, South Africa
    Posts
    484

    Re: UserControl with MSFlexGrid needs Font change

    As long as it's working I'm happy. Thanks LaVolpe.

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