[转]将字体嵌入程序资源中 C# Winform
2020-12-13 02:50
标签:winform style class blog code java [转]将字体嵌入程序资源中 C# Winform,搜素材,soscw.com [转]将字体嵌入程序资源中 C# Winform 标签:winform style class blog code java 原文地址:http://www.cnblogs.com/z5337/p/3785131.htmlnamespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
PrivateFontCollection pfc = new PrivateFontCollection();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string fontName = "WindowsFormsApplication2.汉仪水波体简.ttf";
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream(fontName);
byte[] fontData = new byte[stream.Length];
stream.Read(fontData, 0, (int)stream.Length);
stream.Close();
unsafe
{
fixed (byte* pFontData = fontData)
{
pfc.AddMemoryFont((System.IntPtr)pFontData, fontData.Length);
}
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Font font = new Font(pfc.Families[0], 20);
g.DrawString("测试文字", font, new SolidBrush(Color.Black), 200, 100);
}
}
}
上一篇:网页小记录
下一篇:css浮动和清除浮动