awesome-inc / FontAwesome.Sharp

A library for using Font Awesome in WPF & Windows Forms applications
Apache License 2.0
384 stars 90 forks source link

Font Awesome Sharp Pro DuoToneIcons Support #122

Closed ErickHeredia92 closed 3 months ago

ErickHeredia92 commented 6 months ago

I am currently trying to use Font Awesome Pro in Winforms, I have already managed to use the icons in code (they do not work in the designer, it shows an error) image

This is the code that I used to be able to use the Fonts. In case it can be of help to someone.

/////Get BitMap from TTF File///////

//Get Icon Bitmap from Font Awesome(Default)
PictureBox pictureBox1 = new PictureBox();
pictureBox1.Location = new Point(0,0);
pictureBox1.Name = "pictureBox1";
pictureBox1.Size = new Size(45, 45);
Controls.Add(pictureBox1);            
Image i1 = IconChar.Laptop.ToBitmap(Color.DarkBlue, 48, 0, FlipOrientation.Normal);
pictureBox1.Image = i1;
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;

//Get Icon Bitmap from Material Icons
PictureBox pictureBox2 = new PictureBox();
pictureBox2.Location = new Point(0, 50);
pictureBox2.Name = "pictureBox2";
pictureBox2.Size = new Size(45, 45);
Controls.Add(pictureBox2);
//I get the assembly from "FontAwesome.Sharp.Material.IconImage" because the Font Material is in Nugget Package.
Image i2 = FormsIconHelper.ToBitmap<MaterialIcons>(FormsIconHelper.LoadResourceFont(typeof(FontAwesome.Sharp.Material.IconImage).Assembly, "fonts", "materialdesignicons-webfont.ttf"), MaterialIcons.Laptop, 48, Color.Red, 0, FlipOrientation.Normal);
pictureBox2.Image = i2;
pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;

//Get Icon Bitmap from Font Awesome Pro
PictureBox pictureBox3 = new PictureBox();
pictureBox3.Location = new Point(0, 100);
pictureBox3.Name = "pictureBox2";
pictureBox3.Size = new Size(45, 45);
Controls.Add(pictureBox3);
//I get the assembly from my project form because the Font Pro is in it. 
Image i3 = FormsIconHelper.ToBitmap<ProIcons>(FormsIconHelper.LoadResourceFont(typeof(Form1).Assembly, "fonts", "fa-solid-900-pro.ttf"), ProIcons.LaptopMobile, 48, Color.DarkGreen, 0, FlipOrientation.Normal);
pictureBox3.Image = i3;
pictureBox3.SizeMode = PictureBoxSizeMode.Zoom;

////Create IconButton With Font Awesome Sharp Pro//// 
///
///Before you can create a Font Awesome Pro control or BitMap,
///you must create a Font Awesome Normal or Material Design Icon.
///If this is not done, it gives the same error as when using the designer.
//
FontAwesome.Sharp.Pro.IconButton iconButton = new FontAwesome.Sharp.Pro.IconButton();
iconButton.IconChar = ProIcons.LaptopMobile;
iconButton.IconColor = Color.FromArgb(21, 101, 244); 
iconButton.Size = new Size(50, 50); 
Controls.Add(iconButton);
iconButton.Location = new Point(0, 150);

Note: Before you can create a Font Awesome Pro control or BitMap, you must create a Font Awesome Normal or Material Design Icon. If this is not done, it gives the same error as when using the designer.

And my project is set up this way. (Fonts are marked as Resource)

image

I hope this can be of help to someone since there are no examples of this or at least I couldn't find one.

I'm currently testing to see if I can use FontAwesomePro's Duotone Icons but I can't find a way to use them in Winforms. Do you have any example of what its use would be like?

Or if winforms does not have support for these icons?

mkoertgen commented 5 months ago

Hi @ErickHeredia92 ,

Two quick thoughts about this:

  1. Are your pro-fonts matching the nuget package version?
  2. Did you try regenerating the enum-class and match it with the one provided here in source code?

See