简繁体中文的转换和拼音转换
需要获取 ChineseConverter.dll 和 ChnCharInfo.dll 这两个DLL
可以点击名称下载,也可以通过下载Microsoft Visual Studio International Pack 安装获得这两个DLL
第二种方式请自行搜索下载
以下为测试代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter; using Microsoft.International.Converters.PinYinConverter; namespace ChineseConvertTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void GetTraditional_Click(object sender, EventArgs e) { if (txtSimple.Text == "") { MessageBox.Show("请输入需要转换的中文简体"); return; } char[] CharSimples = txtSimple.Text.Trim().ToCharArray(); for (int i = 0; i < CharSimples.Length; i++) { if (ChineseChar.IsValidChar(CharSimples[i])) { txtTraditional.Text += ChineseConverter.Convert(CharSimples[i].ToString(), ChineseConversionDirection.SimplifiedToTraditional); } else { txtTraditional.Text += CharSimples[i].ToString(); } } } private void txtSimple_TextChanged(object sender, EventArgs e) { //int count = 0; //string simple = ""; //string BiHua = ""; //string PinYin = ""; //char[] CharSimples = txtSimple.Text.Trim().ToCharArray(); //for (int i = 0; i < CharSimples.Length; i++) //{ // if (ChineseChar.IsValidChar(CharSimples[i])) // { // count++; // simple += CharSimples[i].ToString(); // BiHua += ChineseChar.GetStrokeNumber(CharSimples[i]).ToString() + ","; // ChineseChar CC = new ChineseChar(CharSimples[i]); // PinYin += CC.Pinyins[0].Substring(0, CC.Pinyins[0].Length - 1) + ","; // } // else // { // MessageBox.Show("输入的汉字不合法"); // continue; // } //} //label3.Text = string.Format("共有有效汉字{0}个", count); //txtTraditional.Text = ChineseConverter.Convert(simple, ChineseConversionDirection.SimplifiedToTraditional); //txtBiHua.Text = BiHua.Substring(0, BiHua.Length - 1); //txtPinYin.Text = PinYin.Substring(0, PinYin.Length - 1); } private void GetBiHua_Click(object sender, EventArgs e) { string BiHua = ""; char[] CharSimples = txtSimple.Text.Trim().ToCharArray(); for (int i = 0; i < CharSimples.Length; i++) { if (ChineseChar.IsValidChar(CharSimples[i])) { BiHua += ChineseChar.GetStrokeNumber(CharSimples[i]).ToString() + ","; } else { BiHua += "?,"; } } txtBiHua.Text = BiHua.Substring(0, BiHua.Length - 1); } private void GetPinYin_Click(object sender, EventArgs e) { string PinYin = ""; char[] CharSimples = txtSimple.Text.Trim().ToCharArray(); for (int i = 0; i < CharSimples.Length; i++) { if (ChineseChar.IsValidChar(CharSimples[i])) { ChineseChar CC = new ChineseChar((CharSimples[i])); PinYin += CC.Pinyins[0].Substring(0, CC.Pinyins[0].Length - 1) + ","; } else { PinYin += "? ,"; } } txtPinYin.Text = PinYin.Substring(0, PinYin.Length - 1); } } }
以下为测试界面
转载于:https://www.cnblogs.com/ShuiMu/articles/3393767.html