View RSS Feed

Development Team Blog

Change Font of The Statusbar

Rate this Entry
In almost every Visual DataFlex MDI Windows Application you have a statusbar. The statusbar is usually drawn at the bottom of your panel and is divided in one of more panes. Usually the first pane is reserved for statushelp. This blog tells you how you can change the appearance of a CodeJock statusbar and its panes.

Font
Changing the appearance of the statusbar means changing font attributes. The font settings of the statusbar and its panes are not exposed directly via properties defined in the cCJStatusbar of cCJStatusbarPane classes. Like as written in John van Houten's blog about fonts in the grid it is accessible via COM. Once you know how to do this you can change the typeface name, the size, the bold, italics, strikethrough or underline characteristics.

Font Object
To change the font attributes you need to create a cComStdFont object and attach this object to the statusbar or one of the panes and then change the font attributes. There are two places where you can do this. You can change the font settings via the statusbar object or via any of the panes. The font settings in the panes are stronger than the font settings in the statusbar which means that as soon as you changed a setting directly in the pane it will not be overwritten by a setting in the surrounding statusbar object BUT also none of the other attribute changes will come through. This means that if you simply want to change the typeface of all the statusbar panes you better do this in the statusbar object as it requires less coding and is considered more clean coding. If you want the 2nd and 4th pane to be bold instead you need to go via the font settings in the individual panes.

The following code shows how to dynamically create a font object.
Code:
Get Create (RefClass (cComStdFont)) To hoFont
Change Fonts via Statusbar
To change the font settings of all statusbar panes can be done via the statusbar object itself. If you want to do this during object creation use the OnCreate event and attach the font object to the statusbar.

Code:
Object oStatusBar is a cCJStatusBar
    Procedure OnCreate
        Handle hoFont
        Variant vFont
        Boolean bComObjectCreated
        
        Get IsComObjectCreated to bComObjectCreated
        If (bComObjectCreated) Begin        
            Get Create (RefClass (cComStdFont)) to hoFont
    
            Get ComFont to vFont
            If (not (IsNullComObject (vFont))) Begin
                Set pvComObject of hoFont to vFont
            End
        End
    End_Procedure
End_Object
Now you can change any of the cComStdFont properties such as Bold, Italics, Typeface etc. For example if you want to change the typeface add the following line directly under the pvComObject line shown above.
Code:
Set ComName of hoFont to "Verdana"
If you do want to change any other setting you should remove the font object again by sending destroy to the hoFont object. The additions are shown in red in the following code block;
Code:
Object oStatusBar is a cCJStatusBar
    Procedure OnCreate
        Handle hoFont
        Variant vFont
        Boolean bComObjectCreated
        
        Get IsComObjectCreated to bComObjectCreated
        If (bComObjectCreated) Begin        
            Get Create (RefClass (cComStdFont)) to hoFont
    
            Get ComFont to vFont
            If (not (IsNullComObject (vFont))) Begin
                Set pvComObject of hoFont to vFont
                Set ComName of hoFont to "Verdana"
                Send Destroy Of hoFont
            End
        End
    End_Procedure
End_Object
The code can be copied to each of the cCJStatusbarPane objects where you want to change a font setting.

cCJStatusBarEx and cCJStatusBarPaneEx classes
To make it all a bit easier for you I have created subclasses of the cCJStatusbar and cCJStatusbarPane classes and added properties as pbBold, pbItalic, psTypeface which change the font settings either at object construction or on the fly. Your object code can now be:

Code:
Object oStatusBar is a cCJStatusBarEx
    Object oPane1 is a cCJStatusBarPaneEx
        Set piWidth To 100
        Set psText To "Pane 1"
        Set pbBold to True
    End_Object
    
    Object oPane2 is a cCJStatusBarPaneEx
        Set piWidth To 140
        Set psText to "Pane 2"
        Set pnFontHeight to 20
        Set pnFontWeight to 800
    End_Object
    
    Object oPane3 is a cCJStatusBarPaneEx
        Set piWidth To 140
        Set psText to "Pane 3"
        Set psTypeFace to "Verdana"
    End_Object
                
    Object oPane4 is a cCJStatusBarPaneEx
        Set piWidth To 140
        Set pbStrikeThrough to True
        Set psText to "Pane 4"
    End_Object            
End_Object
One remark; if you change the height of the font for the statusbarpane (as shown above) it will not change the height of the statusbar itself and thus clipping off a piece of the text. If you want to have bigger fonts change the height in the statusbar object instead of in the pane object.

Attached to this blog are three classes; two are subclasses of the cCJStatusbar and cCJStatusbarPane classes and the third defines the properties for the classes via a Mixin class. For usage it it snot required to have all three classes active. You can combine a cCJStatubarEx object with cCJStatusbarPane objects or a cCJStatusBar object with cCJStatubarPaneEx objects.

Have fun!
Attached Thumbnails Attached Files

Comments