Изначально я попробовал это, и все сработало, как и ожидалось.
Код: Выделить всё
fontCollection.AddFontFile("./Resources/Circulitos.ttf");У меня есть такой код:
program.cs
Код: Выделить всё
internal static class Program
{
///
/// The main entry point for the application.
///
static private List
_fontCollections;
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(true);
Application.ApplicationExit += delegate {
if (_fontCollections != null)
{
foreach (var fc in _fontCollections) if (fc != null) fc.Dispose();
_fontCollections = null;
}
};
Application.Run(new Main());
}
static public Font GetCustomFont(byte[] fontData, float size, FontStyle style)
{
if (_fontCollections == null) _fontCollections = new List();
PrivateFontCollection fontCol = new PrivateFontCollection();
IntPtr fontPtr = Marshal.AllocCoTaskMem(fontData.Length);
Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
fontCol.AddMemoryFont(fontPtr, fontData.Length);
Marshal.FreeCoTaskMem(fontPtr);
_fontCollections.Add(fontCol);
return new Font(fontCol.Families[0], size, style);
}
}
Код: Выделить всё
public partial class Main : Form
{
private PrivateFontCollection fontCollection;
private Font gf;
public Main()
{
gf = Program.GetCustomFont(Properties.Resources.Circulitos, 10, FontStyle.Regular);
InitializeComponent();
}
private void circulitos(int index, bool update)
{
dataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Green;
dataGridView1.DefaultCellStyle.Font = gf;
dataGridView1.ColumnHeadersDefaultCellStyle.Font = gf;
dataGridView1.RowHeadersDefaultCellStyle.Font = gf;
dataGridView1.EnableHeadersVisualStyles = false;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCell cell = row.Cells[1];
try
{
cell.Style.Font = gf;
}
catch
{
MessageBox.Show("Error fontCollection");
}
label5.Font = gf;
}
dataGridView1.Refresh();
dataGridView1.Invalidate();
}
}
Спасибо, что уделили время
Подробнее здесь: https://stackoverflow.com/questions/787 ... tagridview
Мобильная версия