Sunday, February 10, 2013

Grid Showing Fonts' Name and Appearance

Here is another one that again comes from reading a need of a member inside foxite forum which is to show the list of fonts on the current computer unit in any object possible with an added minor twist, i.e., that aside from the name Arial, the font name should be displayed as well on how the font looks.



And Tushar suggested using a Grid because of its ability to display changing values via its Dynamic Properties.  For this need, utilizing DynamicFontName.  Anyway, here is a simple code to show how Tushar meant by that:


loTest = Createobject("Sample")
loTest.Show(1)

Define Class Sample As Form
Caption = 'Grid Font'
AutoCenter = .T.

Add Object grid1 As Grid With;
ColumnCount = 1,;
AllowCellSelection = .F.,;
GridLines = 0,;
ScrollBars = 2,;
RecordMark = .F.,;
DeleteMark = .F.,;
Top = 10,;
Left = 10,;
Height = 230,;
HeaderHeight = 0,;
RowHeight = 25

Procedure Load
Afont(laFont)

Create Cursor junk (xfont c(20))
For lnloop =1 To Alen(laFont)
Insert Into junk Values (laFont[m.lnloop])
Next
Go Top

Endproc

Procedure grid1.Init
With This
.RecordSourceType =1
.RecordSource = 'junk'
.Column1.DynamicFontName='alltrim(xfont)'
.Column1.Width = 300
.Column1.FontSize = 12
Endwith
Endproc
Enddefine



And because this need is a little unique and basic implementation simple, it now landed among the list of the Grid Tricks shown here in my blogs.  Cheers!


No comments:

Post a Comment