符号字体作为 DataGridView 中的图标

Symbol font as icon in DataGridView

我知道在DataGridview中,我们可以绑定一个ImageColumn到图像数据来显示图标,例如。通常我会使用微软的 MsoImage 图标。

我突然想到,从符号字体,我们可以有很多漂亮的图标。是否可以将列绑定到文本,并考虑字体,以便我们可以使用符号字体并显示看起来像图标的 text + font 的结果。

如果无法进行文本绑定,是否有另一种方法可以extracting/converting将符号字体转换为图像?

您只需为列设置字体即可。这是我的例子:

List<daz> dazz = new List<daz>() { new daz("♻", "267B"), new daz("⚔", "2694") };
Font f = new Font("Segue UI Symbol", 12f);
dataGridView1.DataSource = dazz;
dataGridView1.Columns[0].DefaultCellStyle.Font = f;

忽略示例class:

class daz
{
    public string code { get; set; }
    public string text { get; set; }
    public daz (string c, string t) { code = c;  text = t; }
}