How do I embed my own fonts in a WinForms app?

后端 未结 5 1350
醉酒成梦
醉酒成梦 2020-12-02 15:23

I want to embed fonts in my WinForms application so that I don\'t have to worry about them being installed on the machine. I\'ve searched a bit on the MSDN site and found a

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 16:04

    I dragged and dropped a randomly downloaded font into my resources and this worked. Uses a file though. I guess you can use this as well to install fonts ?

    public Form1()
    {
        string filename = @"C:\lady.gaga";
        File.WriteAllBytes(filename, Resources.KBREINDEERGAMES);
        PrivateFontCollection pfc = new PrivateFontCollection();
        pfc.AddFontFile(filename);
    
        Label label = new Label();
        label.AutoSize = true;
        label.Font = new Font(pfc.Families[0], 16);
        label.Text = "hello world";
        Controls.Add(label);
    }
    

提交回复
热议问题