How to get font info

E

Elmo Watson

I've got the following code that iterates the built-in fonts, and adds them
to a combobox:

Dim ff As FontFamily

For Each ff In System.Drawing.FontFamily.Families

cboFonts.Items.Add(ff.Name)

Next



I've also tried it using:

Dim installedFonts As InstalledFontCollection = New
InstalledFontCollection()

For Each family In installedFonts.Families





What I need to do is get the Font 'information', based on the selected Item
in that combobox.



What I mean by information, is the information that is at the top of the
page/form, when you double-click on any font -

TypeFace name, file size, version, actual file name, opentype or truetype,
copyright info, etc



Can anyone help me/direct me to a code sample, etc, on this?
 
M

Morten Wennevik [C# MVP]

Hi Elmo,

I don't think you can find this information using .Net Framework. A FontFamily is exactly that a, collection of fonts. If you look in the %windir%/Fonts folder you will find most fonts have up to four different files. If you have a font, which of the files do you mean when you want to display the file size (PS make sure you have not Hide Variations set in the View menu)?

I fear you may need to read all the files in %windir%/Fonts and manually find out which file(s) you need, given the FontFamily name and style.

A good starting point would be http://www.wotsit.org/

Not many relevant links found on TTF, but you will at least find a link to the specifications for TTF. Google around for code reading the TTF header which should contain the copyright information etc.
 
E

Elmo Watson

Well then, maybe I'm going about it the wrong way - let's consider fonts
themselves
How would you add the fonts, individually, to the combobox - - then, is
there a way to get this info from the font file?
 
J

Jeff Gaines

Well then, maybe I'm going about it the wrong way - let's consider fonts
themselves
How would you add the fonts, individually, to the combobox - - then, is
there a way to get this info from the font file?

This works for me:

private void LoadFontData()
{
int intCount;
ToolStripMenuItem tsmnuItem;

// Font Names
tsbtnFontName.DropDownItems.Clear();

FontFamily[] sysFonts = FontFamily.Families;
for (intCount = 0; intCount <= sysFonts.GetUpperBound(0); intCount++)
{
tsmnuItem = new ToolStripMenuItem(sysFonts[intCount].Name, null,
tsbtnFontName_DropDownItemClicked);
tsbtnFontName.DropDownItems.Add(tsmnuItem);
}
}

Just use a Combo instead of ToolStripMenu.
 
M

Morten Wennevik [C# MVP]

Well, if the goal is to display available fonts in a ComboBox, this should do

comboBox1.DataSource = FontFamily.Families;
comboBox1.DisplayMember = "Name";

From the selected FontFamily you can create a Font object.


Well then, maybe I'm going about it the wrong way - let's consider fonts
themselves
How would you add the fonts, individually, to the combobox - - then, is
there a way to get this info from the font file?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top