Bind fonts by name with their font style in the ListView in c#

In this article we create a function in c# language that bind all system’s fonts in a Listview control, with the fonts displayed by name in that format. you can see below picture.

This code sample requires a Listview control named ‘ListView1’ on the windows form.

private void BindListView()
	FontFamily objFontFamily = default(FontFamily);
	System.Drawing.Text.FontCollection objFontCollection = null;
	Font tempFont = default(Font);
	objFontCollection = new System.Drawing.Text.InstalledFontCollection();
	foreach ( objFontFamily in objFontCollection.Families) {
		if (objFontFamily.IsStyleAvailable(FontStyle.Regular)) {
			tempFont = new Font(objFontFamily, 14, FontStyle.Regular);
		} else if (objFontFamily.IsStyleAvailable(FontStyle.Bold)) {
			tempFont = new Font(objFontFamily, 14, FontStyle.Bold);
		} else if (objFontFamily.IsStyleAvailable(FontStyle.Italic)) {
			tempFont = new Font(objFontFamily, 14, FontStyle.Italic);
		ListViewItem lst = new ListViewItem();
		lst.Font = tempFont;
		lst.Text = tempFont.FontFamily.Name;

you can see that we get all system fonts by using InstalledFontCollection() method in System.Drawing.Text. This returns a System.Drawing.Text.FontCollection object. and then we find each fontfamily from FontCollection object.