2011-09-13 51 views

Trả lời

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

Lưu ý rằng thư mục Fonts trong liệt kê SpecialFolder chỉ có sẵn trong Net 4 và xa hơn nữa.

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

Đối với câu trả lời ở đây chỉ định Environment.SpecialFolders.Fonts, giá trị điều tra đó chỉ tồn tại trong .NET 4.0+.

Đối với NET 1,1-3,5 bạn có thể làm như sau:

Các thư mục Fonts là bên trong thư mục Windows (ví dụ C: \ Windows \ Fonts). Lập trình lấy nó thông qua các bước sau:

  1. chính ra một thư mục đặc biệt khác nhau mà tồn tại trong giá trị đếm NET 2, giống như thư mục hệ thống Environment.SpecialFolder.System.

  2. Grab thư mục mẹ của thư mục hệ thống (được căn cứ thư mục Windows)

  3. CONCATENATE tên Fonts vào thư mục Windows để có được kết quả cuối cùng.

Mẫu mã này sử dụng thư mục Hệ thống và thực hiện. Có các thư mục khác mà bạn có thể tắt.

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" 
Các vấn đề liên quan