How can I draw font samples from the available fonts

Platform: WinForms| Category: Fonts

James DeBroeck of Microsoft gave this response on the microsoft.public.dotnet.framework.windowsforms.

Here is some C# OnPaint code that will show you how to use FontFamily to get a list of fonts:

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
    int i, nCount;
    SolidBrush  b = new SolidBrush( Color.Black );
    int x = 0, y = 0;

    nCount = FontFamily.Families.Length;
    
    for(i=0;i 0)
	StylesDesc = StylesDesc.Substring(0,StylesDesc.Length-1);

        f = new Font( FontFamily.Families[i].Name, 12, fs);

        String s = FontFamily.Families[i].Name + ' ' + StylesDesc;
        e.Graphics.DrawString( s, f, b, x, y );
        y += f.Height;

    }
}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.