Click here to Skip to main content
13,146,742 members (79,740 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

8.1K views
548 downloads
11 bookmarked
Posted 11 Nov 2016

FontAwesome for WinForms

, 11 Nov 2016
Rate this:
Please Sign up or sign in to vote.
Usage of my FontAwesome Image/Icon generator for WinForms

Introduction

First: many thanks for the font to Font Awesome by Dave Gandy - http://fontawesome.io

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

Background

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:

FontAwesome.SetDownloadLink(null);

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 });

Nuget

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

PM> Install-Package Fkosoft.FontAwesome

Points of Interest

  • C# 4.0, WinForms

History

  • 1.0.0 - First version

License

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

Share

About the Author

Frantisek Ruzicka
Software Developer
Slovakia Slovakia
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionMy vote of 4 ... Pin
DSAlCoda16-Nov-16 7:03
memberDSAlCoda16-Nov-16 7:03 
AnswerRe: My vote of 4 ... Pin
Frantisek Ruzicka16-Nov-16 9:22
memberFrantisek Ruzicka16-Nov-16 9:22 
GeneralRe: My vote of 4 ... Pin
DSAlCoda17-Nov-16 8:59
memberDSAlCoda17-Nov-16 8:59 
GeneralRe: My vote of 4 ... Pin
Frantisek Ruzicka17-Nov-16 10:12
memberFrantisek Ruzicka17-Nov-16 10:12 
General... and ...... 5 Pin
DSAlCoda17-Nov-16 10:23
memberDSAlCoda17-Nov-16 10:23 
GeneralRe: ... and ...... 5 Pin
Frantisek Ruzicka17-Nov-16 10:39
memberFrantisek Ruzicka17-Nov-16 10:39 
GeneralMy vote of 5 Pin
Forhad Reza15-Nov-16 1:17
memberForhad Reza15-Nov-16 1:17 
GeneralRe: My vote of 5 Pin
Frantisek Ruzicka15-Nov-16 2:07
memberFrantisek 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
fkosoft.com12-Nov-16 10:58
memberfkosoft.com12-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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170915.1 | Last Updated 11 Nov 2016
Article Copyright 2016 by Frantisek Ruzicka
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid