本文介绍了紧凑的框架 - 检索国家和地区名单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下午的人!
我想实现我的Compact Framework的县名单(移动)应用程序。
I'm trying to implement a list of counties on my Compact Framework (Mobile) application.
我可以在完整的.NET框架,这样做很容易与CultureInfo.GetCultures(..等)。但是,CF似乎缺少这种功能?
I can do this easily in the full .Net framework with CultureInfo.GetCultures(..etc). However, the CF seems to be missing this feature?
有没有什么办法可以恢复国家的名单(和地区如果可能的话),我可以填充到一个ComboBox?
Is there any way I can return a list of countries (and regions if possible) that I can populate into a ComboBox?
操作系统有国家的名单,所以必须有一个办法做到这一点?
The OS has a list of countries, so there must be a way to do it?
我期待着听到回来了!
I look forward to hearing back!
推荐答案
这个怎么样?
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.InteropServices;
namespace OpenNETCF.Globalization
{
public class CultureInfoHelper
{
private delegate int EnumLocalesHandler(string lpLocaleString);
private static EnumLocalesHandler m_localesDelegate;
private static List<CultureInfo> m_cultures;
private static int EnumLocalesProc(string locale)
{
try
{
m_cultures.Add(CultureInfo.GetCultureInfo(
int.Parse(locale, NumberStyles.HexNumber)));
}
catch
{
// failed for this locale - ignore and continue
}
return 1;
}
public static CultureInfo[] GetCultures()
{
if (m_localesDelegate == null)
{
m_cultures = new List<CultureInfo>();
m_localesDelegate = new EnumLocalesHandler(EnumLocalesProc);
IntPtr fnPtr = Marshal.GetFunctionPointerForDelegate(
m_localesDelegate);
int success = EnumSystemLocales(fnPtr, LCID_INSTALLED);
}
return m_cultures.ToArray();
}
private const int LCID_INSTALLED = 0x01;
private const int LCID_SUPPORTED = 0x02;
[DllImport("coredll", SetLastError = true)]
private static extern int EnumSystemLocales(
IntPtr lpLocaleEnumProc, uint dwFlags);
}
}
使用方法如下:
Usage looks like this:
using OpenNETCF.Globalization;
....
static void Main()
{
foreach (CultureInfo ci in CultureInfoHelper.GetCultures())
{
Debug.WriteLine(string.Format("0x{0:x2}({1}) : {2}", ci.LCID, ci.Name, ci.EnglishName));
}
}
和输出结果如下:
0x402(bg-BG) : Bulgarian (Bulgaria)
0x403(ca-ES) : Catalan (Catalan)
0x405(cs-CZ) : Czech (Czech Republic)
0x406(da-DK) : Danish (Denmark)
0x407(de-DE) : German (Germany)
0x408(el-GR) : Greek (Greece)
0x409(en-US) : English (United States)
...
0x400a(es-BO) : Spanish (Bolivia)
0x440a(es-SV) : Spanish (El Salvador)
0x480a(es-HN) : Spanish (Honduras)
0x4c0a(es-NI) : Spanish (Nicaragua)
0x500a(es-PR) : Spanish (Puerto Rico)
这篇关于紧凑的框架 - 检索国家和地区名单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!