2011-09-13 115 views

回答

33
string fontsfolder = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Fonts); 

注意的是,在SpecialFolder枚舉Fonts文件夾僅在.NET 4.0及以後可用。

5
Environment.SpecialFolders.Fonts 
7
string fontFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Fonts); 
28

對於這裏指定Environment.SpecialFolders.Fonts的答案,枚舉值只存在於.NET 4.0+中。

對於.NET 1.1 - 3.5,你可以做到以下幾點:

字體文件夾是Windows文件夾中(例如C:\ WINDOWS \字體)。編程抓住它通過下列步驟操作:

  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" 
相關問題