Click here to Skip to main content
15,876,639 members
Articles / Programming Languages / C# 4.0

FontAwesome image/icon generator for WinForms

Rate me:
Please Sign up or sign in to vote.
4.92/5 (24 votes)
14 Feb 2018CPOL 56.3K   2.7K   35   19
Usage of my FontAwesome Image/Icon generator for WinForms


First: many thanks for the font to Font Awesome by Dave Gandy -

This is a simple class to create images and icons from FontAwesome TTF.

Image 1


There are some articles describing usage of FontAwesome in WPF. Here is something for good old WinForms.

(Optional) Preset the class with default properties.

//Sample default properties
FontAwesome.DefaultProperties.Size = 32;
FontAwesome.DefaultProperties.ShowBorder = true;

Now, we can start creating images and icons:

//create image using default properties
var image1 = FontAwesome.Type.Crosshairs.AsImage();

//create icon using default properties
var icon = FontAwesome.Type.Crosshairs.AsIcon();

//create image with custom properties
var image2 = new FontAwesome.Properties(FontAwesome.Type.Square) 
{ ForeColor = Color.White }.AsImage();

Sometimes, something more is needed, so I added some simple support for stacking images together:

//sample of stacking images together to create colored unique icons
var stackedImage = 
    new FontAwesome.Properties(FontAwesome.Type.Square) { ForeColor = Color.White }.AsImage()
        .StackWith(new FontAwesome.Properties(FontAwesome.Type.FileO) 
         { Size = 20, Location = new Point(5, 5), ShowBorder = false })
        .StackWith(new FontAwesome.Properties(FontAwesome.Type.Close) 
         { ForeColor = Color.Red, Size = 14, Location = new Point(13, 13), ShowBorder = false });

The FontAwesome class will even download the TTF file:

FontAwesome.Initialize(); //(optional) initiates TTF check and download

You can disable this behaviour by setting:


To use the class with C# 2.0, simply remove the FontAwesomeExtensions class.

//C# 2.0 usage sample
var image1 = FontAwesome.Instance.GetImage(FontAwesome.Type.Save);
var image2 = FontAwesome.Instance.GetImage(new FontAwesome.Properties(FontAwesome.Type.TimesCircle) 
             { ForeColor = Color.Red });
var icon = FontAwesome.Instance.GetIcon(new FontAwesome.Properties(FontAwesome.Type.Home) 
           { ForeColor = Color.Blue, BorderColor = Color.Blue, BackColor = Color.White });

Note: GetIcon() generates a GDI object, which is not automatically released. This can cause exceptions if heavily used. See MSDN article for details.


You can use Nuget to add the library to your project:

PM> Install-Package Fkosoft.FontAwesome

For the new FontAwesome5, there is a new nuget package:

PM> Install-Package Fkosoft.FontAwesome5

Points of Interest

  • C# 4.0, WinForms


  • 1.0.0 - First version
  • 1.0.1 - FontAwesome5 nuget added


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer
Slovakia Slovakia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

GeneralAwesome! Pin
Gopinath K.P26-Apr-20 22:43
Gopinath K.P26-Apr-20 22:43 
QuestionFontAwsome 5 - Initialisation Method missing Pin
David James Tuke25-Jul-18 19:27
professionalDavid James Tuke25-Jul-18 19:27 
AnswerRe: FontAwsome 5 - Initialisation Method missing Pin
Frantisek Ruzicka1-Oct-18 23:26
professionalFrantisek Ruzicka1-Oct-18 23:26 
GeneralMy vote of 5 Pin
Franc Morales18-Jun-18 21:41
Franc Morales18-Jun-18 21:41 
QuestionGithub Pin
SpArtA17-Feb-18 0:21
SpArtA17-Feb-18 0:21 
AnswerRe: Github Pin
Frantisek Ruzicka19-Feb-18 12:47
professionalFrantisek Ruzicka19-Feb-18 12:47 
GeneralMy vote of 5 Pin
Member 1339763814-Feb-18 5:02
Member 1339763814-Feb-18 5:02 
Questionunless you are the creator of the FontAwesome font Pin
BillWoodruff13-Feb-18 4:43
professionalBillWoodruff13-Feb-18 4:43 
AnswerRe: unless you are the creator of the FontAwesome font Pin
Frantisek Ruzicka14-Feb-18 6:21
professionalFrantisek Ruzicka14-Feb-18 6:21 
QuestionMy vote of 4 ... Pin
DSAlCoda16-Nov-16 7:03
DSAlCoda16-Nov-16 7:03 
AnswerRe: My vote of 4 ... Pin
Frantisek Ruzicka16-Nov-16 9:22
professionalFrantisek Ruzicka16-Nov-16 9:22 
GeneralRe: My vote of 4 ... Pin
DSAlCoda17-Nov-16 8:59
DSAlCoda17-Nov-16 8:59 
GeneralRe: My vote of 4 ... Pin
Frantisek Ruzicka17-Nov-16 10:12
professionalFrantisek Ruzicka17-Nov-16 10:12 
General... and ...... 5 Pin
DSAlCoda17-Nov-16 10:23
DSAlCoda17-Nov-16 10:23 
GeneralRe: ... and ...... 5 Pin
Frantisek Ruzicka17-Nov-16 10:39
professionalFrantisek Ruzicka17-Nov-16 10:39 
GeneralMy vote of 5 Pin
Farhad Reza15-Nov-16 1:17
Farhad Reza15-Nov-16 1:17 
GeneralRe: My vote of 5 Pin
Frantisek Ruzicka15-Nov-16 2:07
professionalFrantisek Ruzicka15-Nov-16 2:07 
GeneralMy vote of 5 Pin
wmjordan11-Nov-16 14:42
professionalwmjordan11-Nov-16 14:42 
GeneralRe: My vote of 5 Pin
Frantisek Ruzicka12-Nov-16 10:58
professionalFrantisek Ruzicka12-Nov-16 10:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.