I've found this example... it could be usefull for me if it will run.
But an error occurs: MissingMethodException at FontList_Create()
Please help me!!
' YaoDurant.Drawing.FontCollection.vb - Font enumeration
' wrapper class for FONTLIST.DLL.
' Code from _Programming the .NET Compact Framework with C#_
' and _Programming the .NET Compact Framework with VB_
' (c) Copyright 2002-2003 Paul Yao and David Durant.
' All rights reserved.
Imports System
Imports System.Collections
Imports System.Runtime.InteropServices
Public Class clsFontCollection
Private m_alFaceNames As ArrayList = New ArrayList
' P/Invoke declarations for fontlist.dll
<DllImport("fontlist.DLL")> _
Public Shared Function FontList_Create() As IntPtr
End Function
[snip posted code]
"Francesco Ranieri" <
[email protected]> ha scritto nel messaggio
Hi to all,
I'm using CF 1.0 and VB.net 2003.
I wish to enumerate all the character fonts available into the system, and
the proper size of each one.
The idea is to achieve something like this (pseudo-code):
Dim avilableFonts As Fonts
Dim arraySizesOfThisFont() As Integer
For index=1 to avilableFonts.Count
fontName = avilableFonts(index).name
arrayOfSizesOfThisFont = avilableFonts(index).sizes.toArray()
MyComboBoxFontList.add(fontName)
MyComboBoxCurrentFontSize = arrayOfSizesOfThisFont
Next
and, after selecting a font into first "MyComboBoxFontList", the second
"MyComboBoxCurrentFontSize" fills up with the character sizes of the
selected font.
There's a way to do this?
Thanks in advance
Francesco
First, a friendly reminder that Google Is Your Friend (TM). A search
of this newsgroup for "enumerate" and "font" turns up several relevant
discussions, including one I posted back in March (
http://groups.google.com/group/micr...read/thread/b8415fcc040204f8/a767eab055c88691
).
As it happens, I'm familiar with the book the sample code came from.
Several of their managed demo projects make use of native C++ helper
DLLs. This one is looking for a file called "fontlist.dll". If you
don't have that DLL included in your project, then there's no method
to be found.
I've got one piece of bad news and two pieces of good news for you.
The bad news is that the sample code download page on their website is
no longer working properly, so you can't get fontlist.dll from there.
The good news is that I happen to have both the C# and VB sample
archives stored away, and I've mirrored them on my website at
http://www.isquaredsoftware.com/code.php .
The even better news is that since this question has come up a few
times, and I haven't yet seen a definitive answer, I took some of my
free time today and put together a sample that shows how to do this
using 100% managed code. Note that this _does_ require CF 2.0. I've
uploaded the sample ZIP as EnumFontFamiliesDemo.zip, also available
from
http://www.isquaredsoftware.com/code.php .
For future reference, and for the benefit of the search engines, I've
put the code for Form1 at the bottom. All necessary structures have
been declared in another file, based on the definitions in MSDN.
Hope this helps!
Mark Erikson
http://www.isquaredsoftware.com
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using FI = EnumFontFamiliesDemo.FontInformation;
namespace EnumFontFamiliesDemo
{
// See description of EnumFontFamProc on MSDN
delegate int EnumFontDelegate(IntPtr lpelfe, IntPtr lpntme, int
FontType, int lParam);
public partial class Form1 : Form
{
private List<string> fontNames;
IntPtr fpEnumProc;
EnumFontDelegate enumFontDelegate;
[DllImport("coredll.dll")]
private static extern int EnumFontFamilies(IntPtr hdc, string
fontFamily, IntPtr lpEnumFontFamExProc, IntPtr lParam);
[DllImport("coredll.dll")]
private static extern IntPtr GetDesktopWindow();
[DllImport("coredll.dll")]
private static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("coredll.dll")]
private static extern IntPtr ReleaseDC(IntPtr hdc);
public Form1()
{
InitializeComponent();
fontNames = new List<string>();
}
public int EnumFontFamiliesExProc(IntPtr lpelfe, IntPtr lpntme, int
FontType, int lParam)
{
FI.LOGFONT logFont = (FI.LOGFONT)Marshal.PtrToStructure(lpelfe,
typeof(FI.LOGFONT));
fontNames.Add(logFont.lfFaceName);
// Non-zero return continues enumerating
return 1;
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
// Need an HDC to pass to EnumFontFamilies
IntPtr hwnd = GetDesktopWindow();
IntPtr hdc = GetDC(hwnd);
FI.LOGFONT logFont = new FontInformation.LOGFONT();
enumFontDelegate = new EnumFontDelegate(EnumFontFamiliesExProc);
fpEnumProc =
Marshal.GetFunctionPointerForDelegate(enumFontDelegate);
EnumFontFamilies(hdc, null, fpEnumProc, IntPtr.Zero);
// We got a list of the major families. Copy the list,
// then clear it so we can go back and grab all the individual
fonts.
List<string> fontFamilies = new List<string>();
fontFamilies.AddRange(fontNames);
fontNames.Clear();
foreach(string fontFamily in fontFamilies)
{
EnumFontFamilies(hdc, fontFamily, fpEnumProc, IntPtr.Zero);
}
ReleaseDC(hdc);
foreach(string s in fontNames)
{
listBox1.Items.Add(s);
}
}
}
}