📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
using System.IO;
namespace PrivateFont
{
public partial class MainForm : Form
{
private static IntPtr HWND_BROADCAST = new IntPtr(0xffff);
private static uint WM_FONTCHANGE = 0x001D;
[DllImport ("CoreDll.dll")]
private static extern int AddFontResource(string FileName);
[DllImport("CoreDll.dll")]
private static extern bool RemoveFontResource(string FileName);
[DllImport ("CoreDll.dll")]
private static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
[DllImport("CoreDll.dll")]
private static extern uint GetLastError();
private string ExePath;
public MainForm()
{
InitializeComponent();
}
private void btnLoad_Click(object sender, EventArgs e)
{
int i = AddFontResource(@"\Storage Card\xujinglei.fon");
long result = SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
}
private void btnUnload_Click(object sender, EventArgs e)
{
bool r = RemoveFontResource(@"\Storage Card\xujinglei.fon");
if (!r)
{
MessageBox.Show(GetLastError().ToString());
}
long result = SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
InstalledFontCollection fonts = new InstalledFontCollection();
}
private void cboFonts_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void MainForm_Load(object sender, EventArgs e)
{
string codeBase = Assembly.GetExecutingAssembly().GetName().CodeBase;
ExePath = Path.GetDirectoryName(codeBase);
//DirectoryInfo dir = new DirectoryInfo(ExePath);
DirectoryInfo dir = new DirectoryInfo(@"\Storage Card\");
FileInfo[] fontFiles = dir.GetFiles("*.ttf");
foreach (FileInfo fi in fontFiles)
{
lstFonts.Items.Add(new ListViewItem(fi.Name));
AddFontResource(fi.FullName);
}
long result = SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
}
private void menuItem7_Click(object sender, EventArgs e)
{
MessageBox.Show("Powered by Manfeel\nmingtao@sina.com");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -