property Items.CellFont ([Item as Variant], [ColIndex as Variant]) as IFontDisp
Retrieves or sets the cell's font.

 TypeDescription 
   Item as Variant A long expression that indicates the item's handle, or optional if the cell's handle is passed to ColIndex parameter  
   ColIndex as Variant A long expression that indicates the column's index or cell's handle, or a string expression that indicates the column's caption.  
   IFontDisp A Font object that indicates the cell's font.  

By default, the CellFont property is nothing. If the CellFont property is noting, the cell uses the item's font.  Use the CellFont and ItemFont properties to specify different fonts for cells or items. Use the CellBold, CellItalic, CellUnderline, CellStrikeout, ItemBold, ItemUnderline, ItemStrikeout, ItemItalic or CellCaptionFormat to specify different font attributes. Use the Refresh method to refresh the control's content on the fly. Use the BeginUpdate and EndUpdate methods if you are doing multiple changes, so no need for an update each time a change is done.

The following VB sample changes the font for the focused cell:

With Gantt1.Items
    .CellFont(.FocusItem, 0) = Gantt1.Font
    With .CellFont(.FocusItem, 0)
        .Name = "Comic Sans MS"
        .Size = 10
        .Bold = True
    End With
End With
Gantt1.Refresh

The following C++ sample changes the font for the focused cell:

#include "Items.h"
#include "Font.h"
CItems items = m_gantt.GetItems();
COleVariant vtItem(items.GetFocusItem()), vtColumn( (long)0 );
items.SetCellFont( vtItem, vtColumn, m_gantt.GetFont().m_lpDispatch );
COleFont font = items.GetCellFont( vtItem, vtColumn );
font.SetName( "Comic Sans MS" );
font.SetBold( TRUE );
m_gantt.Refresh();

The following VB.NET sample changes the font for the focused cell:

With AxGantt1.Items
    .CellFont(.FocusItem, 0) = IFDH.GetIFontDisp(AxGantt1.Font)
    With .CellFont(.FocusItem, 0)
        .Name = "Comic Sans MS"
        .Bold = True
    End With
End With
AxGantt1.CtlRefresh()

where the IFDH class is defined like follows:

Public Class IFDH
    Inherits System.Windows.Forms.AxHost

    Sub New()
        MyBase.New("")
    End Sub

    Public Shared Function GetIFontDisp(ByVal font As Font) As Object
        GetIFontDisp = AxHost.GetIFontFromFont(font)
    End Function

End Class

The following C# sample changes the font for the focused cell:

axGantt1.Items.set_CellFont( axGantt1.Items.FocusItem, 0, IFDH.GetIFontDisp( axGantt1.Font ) );
stdole.IFontDisp spFont = axGantt1.Items.get_CellFont(axGantt1.Items.FocusItem, 0 );
spFont.Name = "Comic Sans MS";
spFont.Bold = true;
axGantt1.CtlRefresh();

where the IFDH class is defined like follows:

internal class IFDH : System.Windows.Forms.AxHost
{
	public IFDH() : base("")
	{
	}

	public static stdole.IFontDisp GetIFontDisp(System.Drawing.Font font)
	{
		return System.Windows.Forms.AxHost.GetIFontFromFont(font) as stdole.IFontDisp;
	}
}

The following VFP sample changes the font for the focused cell:

with thisform.Gantt1.Items
	.DefaultItem = .FocusItem
	.CellFont(0,0) = thisform.Gantt1.Font
	with .CellFont(0,0)
		.Name = "Comic Sans MS"
		.Bold = .t.
	endwith
endwith
thisform.Gantt1.Object.Refresh()

Send comments on this topic.
1999-2017 Exontrol.COM, Software. All rights reserved.