public class CustomFont
{
public string ChangeFont(string font, string target)
{
PrivateFontCollection pfc = new PrivateFontCollection();
int fontLength = Properties.Resources.font.Length;
byte[] fontdata = Properties.Resources.font;
System.IntPtr data = Marshal.AllocCoTaskMem(fontLength);
Marshal.Copy(fontdata, 0, data, fontLength);
pfc.AddMemoryFont(data, fontLength);
target.Font = new Font(pfc.Families[0], target.Font.Size);
}
}
I tried this but errors were shown that 'App.Properties.Resources' does not contain a definition for 'font'.
Okay so I edited the code following everybody's answers and it is almost working now. The problem is, what method should I use for byte[]
?
public void ChangeFont(string font, TextBox target)
{
PrivateFontCollection pfc = new PrivateFontCollection();
int fontLength = Properties.Resources.ResourceManager.GetString(font).Length;
byte[] fontdata = Properties.Resources.font;
System.IntPtr data = Marshal.AllocCoTaskMem(fontLength);
Marshal.Copy(fontdata, 0, data, fontLength);
pfc.AddMemoryFont(data, fontLength);
target.Font = new Font(pfc.Families[0], target.Font.Size);
}