Now it’s time to apply icon fonts in a real-world scenario. 0xe700, 0xe710, 0xe720 - are icon font's unicode from the WF Fabric.ttf file. IconChar = char.ConvertFromUtf32(IconFont.Paint) Į.Graphics.DrawString(iconChar, iconFont, new SolidBrush(Color.Green), new PointF(70, 70)) Icon font's unicode "0xe720" is converted to string and drawn using e.Graphics with WF Fabric set as font family. IconChar = char.ConvertFromUtf32(IconFont.Plus) Į.Graphics.DrawString(iconChar, iconFont, new SolidBrush(Color.Red), new PointF(40, 40)) Icon font's unicode "0xe710" is converted to string and drawn using e.Graphics with WF Fabric set as font family. String iconChar = char.ConvertFromUtf32(IconFont.LastArrow) įont iconFont = new Font(pfc.Families, 18.5f, FontStyle.Bold) Į.Graphics.DrawString(iconChar, iconFont, new SolidBrush(Color.Orange), new PointF(10, 10)) Icon font's unicode "0xe700" is converted to string and drawn using e.Graphics with WF Fabric set as font family. Extracting icon fonts from the WF Fabric.ttf file and inserting into system memory. So, wherever you draw using the icon font, the Unicode will be converted as a string and passed as a parameter to the DrawString method. Now create an enumeration with all the icon fonts with the appropriate name and assign its Unicode with the prefix 0x. As mentioned, we created the WF Fabric.ttf with a font family name of WF Fabric. The Families property inside the pfc object will hold saved font family names. The pfc instance of the PrivateFontCollection class plays a vital role by saving private or custom icon fonts in system memory. Pfc.AddMemoryFont(memPointer, fontAsByte.Length) Copy(fontAsByte, 0, memPointer, fontAsByte.Length) IntPtr memPointer = .AllocHGlobal(.SizeOf(typeof(byte)) * fontAsByte.Length) Stream fontAsStream = this.GetType().Assembly.GetManifestResourceStream("WindowsFormsApp1.WF Fabric.ttf") īyte fontAsByte = new byte įontAsStream.Read(fontAsByte, 0, (int)fontAsStream.Length) Extracting icon fonts from the WF Fabric.ttf file and adding into system memory. PrivateFontCollection pfc = new PrivateFontCollection() Private void Form1_Paint(object sender, PaintEventArgs e) Like other fonts (Arial, Times New Roman, etc.) WF Fabric will also be registered in the system memory in Control Panel\All Control Panel Items\Fonts.
WF Fabric.ttf File Marked as Embedded Resourceĭuring form initialization, include the code to register icon fonts in the system memory. Include the WF Fabric.ttf file in your WinForms application and mark its Build Action as Embedded Resource in the properties dialog. Note: The Unicode shown in the previous figure (e700, e701, etc.) represents a respective glyph when being drawn in an application. ttf file that has a font family named “WF Fabric.” The resultant icons are shown in the following figure.
One offline tool, called Metro Studio, is provided free by Syncfusion.įor demonstration, we created a. There are many online and offline applications that support creating icon fonts. The fonts typically available in a system, like Arial and Times New Roman, may not have the icons we need to use in our applications. We don’t have to worry about maintaining images of different sizes for different DPI scaling. Remember, in the case of DPI, all we need to do is to change the font size. The question that often comes to everyone’s mind is, “Can icon fonts be used in WinForms, a desktop application?” Yes, it can. The only limitation is that a single icon can only be drawn in one color. Since they are vector graphics, users can scale them up and down without losing quality. In web technology, icon fonts are dominate compared to other image formats. Icon fonts contain symbols instead of numbers and letters.
BoldSign – Electronic Signature Software.