How to set a custom font in a WinForms Grid without installing it on the machine?
To draw the WinForms GridControl with a custom font or a private font without installing it on the machine, use the AddMemoryFont method of Syncfusion.Drawing.FontUtil class.
Code Snippet
public Form1()
{
axelFont = InitializeResourceFont(Properties.Resources.Axel_Regular);
//Setting the font to grid.
gridControl1.Font = new Font(axelFont.FontFamily, 15);
}
private Font InitializeResourceFont(byte[] resourceFont)
{
byte[] fontData = resourceFont;
fonts.AddFontFile(@"..\..\Resources\Axel-Regular.ttf");
IntPtr fontPtr = Marshal.AllocCoTaskMem(fontData.Length);
Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
//To draw the font using Syncfusion drawing to use the private font collections
FontUtil.AddMemoryFont(fontPtr, resourceFont.Length);
Marshal.FreeCoTaskMem(fontPtr);
return new Font(fonts.Families[0], 9.00F);
}Public Sub New()
axelFont = InitializeResourceFont(My.Resources.Axel_Regular
'Setting the font to grid.
gridControl1.Font = New Font(axelFont.FontFamily, 15)
End Sub
Private Function InitializeResourceFont(ByVal resourceFont() As Byte) As Font
Dim fontData() As Byte = resourceFont
fonts.AddFontFile("..\..\Resources\Axel-Regular.ttf")
Dim fontPtr As IntPtr = Marshal.AllocCoTaskMem(fontData.Length)
Marshal.Copy(fontData, 0, fontPtr, fontData.Length)
'To draw the font using Syncfusion drawing to use the private font collections
FontUtil.AddMemoryFont(fontPtr, resourceFont.Length)
Marshal.FreeCoTaskMem(fontPtr)
Return New Font(fonts.Families(0), 9.00F)
End FunctionThe
screenshot below displays the custom fonts added to the grid.

Sample Links:
C#: Adding custom font to grid_CS
VB: Adding custom font to grid_VB
Conclusion
I hope you enjoyed learning about how to set the custom font to WinForms Grid without installing it in the machine.
You can refer to our WinForms GridControl feature tour page to know about its other groundbreaking feature representations and WinForms GridControl documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!