• 【转】C#安装字体到系统


       [DllImport("kernel32.dll", SetLastError = true)]
            
    static extern int WriteProfileString(string lpszSection, string lpszKeyName, string lpszString);

            [DllImport("user32.dll")]
            
    public static extern int SendMessage(int hWnd, // handle to destination window 
            uint Msg, // message 
            int wParam, // first message parameter 
            int lParam // second message parameter 
            );

            [DllImport("gdi32")]
            
    public static extern int AddFontResource(string lpFileName);
              
            
    private void installFont()
            {

                string WinFontDir = "C:\\windows\\fonts";
                
    string FontFileName = "DS-Digital Bold Italic.TTF";
                
    string FontName = "DS-Digital Bold Italic";
                
    int Ret;
                
    int Res;
                
    string FontPath;
                
    const int WM_FONTCHANGE = 0x001D;
                
    const int HWND_BROADCAST = 0xffff;
                FontPath 
    = WinFontDir + "\\" + FontFileName;
                
    if (!File.Exists(FontPath))
                {
                    File.Copy(System.Windows.Forms.Application.StartupPath 
    + "\\DS-Digital Bold Italic.TTF", FontPath);
                    Ret 
    = AddFontResource(FontPath);

                    Res = SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 00);
                    Ret 
    = WriteProfileString("fonts", FontName + "(TrueType)", FontFileName);
                }
            }

  • 相关阅读:
    nginx+iis使用
    sqlserver中一些常用的函数总结
    HTML如何让文字居中?附两种方式
    PNG图片收集
    解决mac pro 软件损坏
    end-of-file from the keyboard
    c++while控制语句
    如何通过命令行编写调试第一个C++程序(UNIX)
    matlab直接运行fig文件时报错
    第二次结对编程作业
  • 原文地址:https://www.cnblogs.com/vic_lu/p/2827908.html
Copyright © 2020-2023  润新知