This blog has moved!

Check out www.CodeBetter.com/blogs/grant.killian

<October 2008>
SuMoTuWeThFrSa
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678


Navigation

Professional Props...

Extracurricular Props...

Subscriptions

Article Categories



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!

posted on Wednesday, November 17, 2004 10:20 AM by grant.killian





Powered by Dot Net Junkies, by Telligent Systems