// 一、使用资源文件(内存)中的字体 System.Runtime.InteropServices.GCHandle hObject = System.Runtime.InteropServices.GCHandle.Alloc(Properties.Resources.QuartzMS, System.Runtime.InteropServices.GCHandleType.Pinned); IntPtr intptr = hObject.AddrOfPinnedObject(); System.Drawing.Text.PrivateFontCollection fc = new System.Drawing.Text.PrivateFontCollection(); fc.AddMemoryFont(intptr, Properties.Resources.QuartzMS.Length); Font font1 = new Font(fc.Families[0], 20); label1.UseCompatibleTextRendering = true; //这句很关键 label1.Text = "0123456789"; label1.Font = font1;
// 二、使用文件中的字体 System.Drawing.Text.PrivateFontCollection fc = new System.Drawing.Text.PrivateFontCollection(); fc.AddFontFile("x:\\QuartzMS.ttf"); Font font1 = new Font(fc.Families[0], 20); label1.Text = "0123456789"; label1.Font = font1;
时间: 2024-10-07 07:04:31