Time well forgotten
As I said in my previous post, I've been doing a lot of unmanaged windows development lately. I started work on a proof-of-concept for a different project where I need to present a list of fonts for the user to select from. My first thought was windows API here I come. I scared up the following interop code:
[DllImport( "gdi32", EntryPoint="EnumFontFamiliesEx" ) ] public static extern int EnumFontFamiliesExA( int hDC, ref LOGFONT lpLogFont, int lpEnumFontProc, int lParam, int dw )
Luckily for me I didn't pursue this route for long. It dawned on me like a fresh pair of socks, all warm and snug from the dryer: Microsoft has exposed a new set of APIs through the .Net framework that allows easier, object oriented access to resources like the available system fonts. Duh! A quick perusal of some documentation brought me to this:
cboFont.DataTextField = "name" ;
cboFont.DataSource = new System.Drawing.Text.InstalledFontCollection().Families ;
cboFont.DataBind() ;
Ah, sweet nourishing System.Drawing.Text.InstalledFontCollection().Families. It's going to take me a little while to forget the last month or so of unmanaged debugging . . . but it will be time well forgotten!