[英]Get a list of installed languages in Windows 10
我需要在WPF
應用程序的ComboBox
中顯示已安裝語言的列表。 例如,我安裝了英語(美國)和英語(印度)。 我想在我的ComboBox
顯示這兩個
我為此使用CultureInfo
類。 以下是我正在嘗試的片段。 我能夠得到所有的文化。 但是我只需要通過系統設置安裝的區域性即可。
var cultureInfos = CultureInfo.GetCultures(CultureTypes.NeutralCultures);
foreach (var culture in cultureInfos)
{
Console.WriteLine(culture.Name);
}
您可以使用本機函數GetKeyboardLayoutList
來獲取已安裝輸入語言的列表。
這是一個示例:
IEnumerable<CultureInfo> GetInstalledInputLanguages()
{
// first determine the number of installed languages
uint size = GetKeyboardLayoutList(0, null);
IntPtr[] ids = new IntPtr[size];
// then get the handles list of those languages
GetKeyboardLayoutList(ids.Length, ids);
foreach (int id in ids) // note the explicit cast IntPtr -> int
{
yield return new CultureInfo(id & 0xFFFF);
}
}
[DllImport("user32.dll")]
static extern uint GetKeyboardLayoutList(int nBuff, [Out] IntPtr [] lpList);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.