This function adds the font resource from the specified file to the Windows font table. The font can subsequently be used for text output by any Microsoft? Windows? CE–based application.
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
namespace SmartDeviceProject1
{
public partial class Form1 : Form
{
private static IntPtr HWND_BROADCAST = new IntPtr(0xffff);
private static IntPtr HWND_TOP = new IntPtr(0);
private static IntPtr HWND_BOTTOM = new IntPtr(1);
private static IntPtr HWND_TOPMOST = new IntPtr(-1);
private static IntPtr HWND_NOTOPMOST = new IntPtr(-2);
private static IntPtr HWND_MESSAGE = new IntPtr(-3);
int ret = AddFontResource("d:\\download\\Ni7seg.ttf"); //这里执行完以后ret=0,表示失败,不知为何?
long result = SendMessage(HWND_BROADCAST, WindowsMessages.WM_FONTCHANGE, IntPtr.Zero, IntPtr.Zero);
this.label1.Font = new System.Drawing.Font("NI7SEG", 72F, System.Drawing.FontStyle.Bold);
this.label1.Location = new System.Drawing.Point(12, 148);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(787, 173);
this.label1.Text = "1.234567890";
}