1.using System.Runtime.InteropServices;
2.import kernel32.dll
- [DllImport("kernel32.dll",EntryPoint = "LCMapStringA")]
- public static extern int LCMapString(int Locale,int dwMapFlags,byte[] lpSrcStr,int cchSrc,byte[] lpDestStr,int cchDest);
- const int LCMAP_SIMPLIFIED_CHINESE = 0x02000000;
- const int LCMAP_TRADITIONAL_CHINESE = 0x04000000;
3.转简体
- private void btnCHS_Click(object sender, EventArgs e)
- {
- string src = txtSrcText.Text.Trim();
- byte[] srcByte = Encoding.Default.GetBytes(src);
- byte[] desByte = new byte[srcByte.Length];
- LCMapString(2052, LCMAP_SIMPLIFIED_CHINESE, srcByte, -1, desByte, srcByte.Length);
- string des = Encoding.Default.GetString(desByte);
- txtDesText.Text = des;
- }
4.转繁体
- private void btnCHT_Click(object sender, EventArgs e)
- {
- string src = txtSrcText.Text.Trim();
- byte[] srcByte = Encoding.Default.GetBytes(src);
- byte[] desByte = new byte[srcByte.Length];
- LCMapString(2052, LCMAP_TRADITIONAL_CHINESE, srcByte, -1, desByte, srcByte.Length);
- string des = Encoding.Default.GetString(desByte);
- txtDesText.Text = des;
- }
5.关于前一篇C#简繁体转换方法(Microsoft.VisualBasic.dll)有朋友提到“余”不能转换“餘”的问题,在本篇方法同样没有解决,:-(。小弟找了N多资料&他人程式,webservice同样没有解决,除非用字库。不过在Office 2003简繁体转换加载项的确可以解决,目前正从这方面思考,若有答案再贴出跟朋友讨论。