添加引用:
using Microsoft.Win32;
public class RegistryKeyHelper
{
private const string _RegisterKey = "CultureInfo_Language";
private const string _CurrentLang = "CultureInfo";
/// <summary>
/// Get System language
/// </summary>
/// <returns></returns>
public static string GetSysLang()
{
RegistryKey key = Registry.CurrentUser;
RegistryKey softWare = key.OpenSubKey(_RegisterKey, true);
if (softWare == null)
{
//默认创建
SetSysLang("en-US");
return "en-US";
}
return softWare.GetValue(_CurrentLang).ToString();
}
/// <summary>
/// Set system language
/// </summary>
/// <param name="lang"></param>
public static void SetSysLang(string lang)
{
RegistryKey key = Registry.CurrentUser;
RegistryKey softWare = key.OpenSubKey(_RegisterKey, true);
if (softWare == null)
{
softWare = key.CreateSubKey(_RegisterKey);
}
softWare.SetValue(_CurrentLang, lang);
}
/// <summary>
/// Delete system language
/// </summary>
public static void DelSysLang()
{
RegistryKey key = Registry.CurrentUser;
RegistryKey softWare = key.OpenSubKey("software\\CultureInfo_Language", true);
softWare.Close();
}
}