【问题标题】:How to get the path to the Windows fonts folder?如何获取 Windows 字体文件夹的路径?
【发布时间】:2011-11-16 11:41:28
【问题描述】:

我正在使用 C# 来获取系统字体文件夹的确切路径。 找不到执行此操作的类/dll。

【问题讨论】:

    标签: c# .net fonts path directory


    【解决方案1】:
    Environment.SpecialFolders.Fonts
    

    【讨论】:

      【解决方案2】:
      string fontFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
      

      【讨论】:

        【解决方案3】:
        string fontsfolder = System.Environment.GetFolderPath(
        System.Environment.SpecialFolder.Fonts);
        

        请注意,SpecialFolder 枚举中的 Fonts 文件夹仅在 .Net 4 及更高版本中可用。

        【讨论】:

          【解决方案4】:

          对于此处指定 Environment.SpecialFolders.Fonts 的答案,该枚举值仅存在于 .NET 4.0+ 中。

          对于 .NET 1.1 - 3.5,您可以执行以下操作:

          字体文件夹位于 Windows 文件夹内(例如 C:\Windows\Fonts)。通过以下步骤以编程方式获取它:

          1. 关闭另一个在 .NET 2 的枚举值中确实存在的特殊文件夹,例如系统文件夹 Environment.SpecialFolder.System

          2. 抓取系统文件夹的父文件夹(获取基础Windows文件夹)

          3. 将字体名称连接到 Windows 文件夹以获得最终结果。

          此代码示例使用 System 文件夹并执行此操作。您可以关闭其他文件夹。

          using System.IO;
          
          // get parent of System folder to have Windows folder
          DirectoryInfo dirWindowsFolder = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.System));
          
          // Concatenate Fonts folder onto Windows folder.
          string strFontsFolder = Path.Combine(dirWindowsFolder.FullName, "Fonts");
          
          // Results in full path e.g. "C:\Windows\Fonts"
          

          【讨论】:

            猜你喜欢
            • 2023-03-26
            • 1970-01-01
            • 1970-01-01
            • 2014-05-29
            • 1970-01-01
            • 1970-01-01
            • 2011-05-20
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多