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.VisualBasic;
using System.Globalization;
using MetroFramework.Forms;
namespace PinyinTest
{
public partial class Form1 : MetroForm
{
TextInfo myTI = new CultureInfo("en-US", false).TextInfo;
public Form1()
{
InitializeComponent();
}
private void metroButton1_Click(object sender, EventArgs e)
{
//直接利用TextBox元件的Lines屬性即可得到以列為單位的字串陣列(string[])
string[] strChinese = (!String.IsNullOrEmpty(txtChinese.Text.Trim())) ? txtChinese.Lines : null;
string strPinyin = "";
foreach (string str in strChinese) {
//將繁體中文字轉換成簡體中文
//簡體中文 (GB2312) 系統的 LocaleID (LCID) 為 2052
string strCN = Strings.StrConv(str, VbStrConv.SimplifiedChinese, 2052);
//轉換成拼音
string pinyin = NPinyin.Pinyin.GetPinyin(strCN);
strPinyin += pinyin + "\r\n";
}
txtPinyin.Text = myTI.ToTitleCase(strPinyin);
}
}
}