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.
FontAwesome.DefaultProperties.Size = 32;
FontAwesome.DefaultProperties.ShowBorder = true;
Now, we can start creating images and icons:
var image1 = FontAwesome.Type.Crosshairs.AsImage();
var icon = FontAwesome.Type.Crosshairs.AsIcon();
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:
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();
You can disable this behaviour by setting:
FontAwesome.SetDownloadLink(null);
To use the class with C# 2.0, simply remove the FontAwesomeExtensions
class.
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.
Nuget
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
History
- 1.0.0 - First version
- 1.0.1 -
FontAwesome5
nuget added