C#中根据注册表查找字体与字体文件路径对应关系
来源:互联网 发布:淘宝金钻买家 编辑:程序博客网 时间:2024/05/17 02:35
private SortedDictionary<string, string> ReadFontInformation() { var dictionary = new SortedDictionary<string, string>(); RegistryKey mykey = Registry.LocalMachine; // 打开注册表 RegistryKey mykeySub = mykey.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts", true); //获取字体名 string[] mynames = mykeySub.GetValueNames(); foreach (string name in mynames) { //获取字体的文件名 string myvalue = mykeySub.GetValue(name).ToString(); if (myvalue.Substring(myvalue.Length - 4).ToUpper() == ".TTF" && myvalue.Substring(1, 2).ToUpper() != @":\") { string val = name.Substring(0, name.Length - 11); dictionary[val] = myvalue; } } mykeySub.Close(); return dictionary; }