• 用C#字体在应用程序启动:如何安装OpenType字体(OTF文件类型)

  • 本文关于 c#,pinvoke
  • CodeGo.net > 用C#字体在应用程序启动:如何安装OpenType字体(OTF文件类型)
  •  

    用C#字体在应用程序启动:如何安装OpenType字体(OTF文件类型)



    c# pinvoke
    我还需要安装一个无数亲网页。 OTF字体在客户端端的C#。请建议。我试图在安装后按照本
     [DllImport("gdi32", EntryPoint = "AddFontResource")]
     public static extern int AddFontResourceA(string lpFileName);
     [System.Runtime.InteropServices.DllImport("shfolder.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
     private static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder,
     IntPtr hToken, int dwFlags, StringBuilder lpszPath);
     private const int CSIDL_FONTS = 0x0014;
     private const int MAX_PATH = 260;
     // PInvoke to 'register' fonts and broadcast addition
     [System.Runtime.InteropServices.DllImport("gdi32.dll")]
     private static extern int AddFontResource(string lpszFilename);
     [System.Runtime.InteropServices.DllImport("gdi32.dll")]
     private static extern int CreateScalableFontResource(uint fdwHidden, string
     lpszFontRes, string lpszFontFile, string lpszCurrentPath);
     private static IntPtr HWND_BROADCAST = new IntPtr(0xffff);
     private const uint WM_FONTCHANGE = 0x001D;
     public Window1()
     {
      InitializeComponent();
      InstallFont();
     }
     internal static void InstallFont()
     {
      string fontsPath = GetFontsPath();
      string ttfFile = System.IO.Path.Combine(fontsPath, "MyriadPro-Semibold.otf");
      System.IO.File.Copy(@"C:\MyriadPro-Semibold.otf", ttfFile);
      int ret;
      if (System.IO.File.Exists(ttfFile))
      {
       //Add font resource
       ret = AddFontResource(ttfFile);
       //Add registry entry so the font is also available next session
       Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts",
        "MyriadPro-Semibold(TrueType)", "MyriadPro-Semibold.otf", RegistryValueKind.String);
       //Broadcast to let all top-level windows know about change
       ret = SendMessage(HWND_BROADCAST, WM_FONTCHANGE, new IntPtr(0), new IntPtr(0));
      }
     }
    
     private static string GetFontsPath()
     {
      StringBuilder sb = new StringBuilder(MAX_PATH);
      SHGetFolderPath(IntPtr.Zero, CSIDL_FONTS, IntPtr.Zero, 0, sb);
      return sb.ToString();
     }
     [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
     private static extern int SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,IntPtr lParam);
    }
    
    执行该代码后,我可以看到在注册表中的条目,也被复制到系统字体文件夹,但我不能够从Microsoft Office Word中查看的字体。 我失去任何东西在这里?
    本文地址 :CodeGo.net/1482667/
    -------------------------------------------------------------------------------------------------------------------------
    1.哪里是说:
    Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts",
        "MyriadPro-Semibold(TrueType)", "MyriadPro-Semibold.otf", RegistryValueKind.String);
    
    这难道不应该是
    Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts",
        "MyriadPro-Semibold(TrueType)", "C:\windows\fonts\MyriadPro-Semibold.otf", RegistryValueKind.String);
    
    哪里
    C:\windows\fonts\
    
    是字体文件夹?
    本文标题 :用C#字体在应用程序启动:如何安装OpenType字体(OTF文件类型)
    本文地址 :CodeGo.net/1482667/
    1. using System.Data
    2. 。MDF文件和跨数据库查询?
    3. 将bool[] SendData= new bool[40960];保存为一个文件,有什么办法不?
    4. 为什么Thread.Join不让通过COM消息?
    5. Socket进程阻塞AcceptSocket()卡死!救
    6. 无法读取的True Type字体文件在我的WPF应用程序!
    7. C# winform中的flowlayoutpanel
    8. 设置ComboBox.SelectedIndexrestOneWayToSourceconstraints力ComboBox.SelectedItem
    9. winform传参问题
    10. 如何修改在数据表中的数据在C#

     
    

    Copyright © 2017 CodeGo.net
    http://codego.net/xinwen/ 足球比分网 足球比分 医药招商网 邵阳县新闻