//PingYin.cs文件
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Text;namespace PinYin
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ListBox listBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
 InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
// 
// textBox1
// 
this.textBox1.Location = new System.Drawing.Point(24, 8);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(280, 152);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
// 
// textBox2
// 
this.textBox2.Location = new System.Drawing.Point(24, 184);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(136, 21);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
this.textBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox2_KeyPress);
this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
// 
// label1
// 
this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(0, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(24, 48);
this.label1.TabIndex = 2;
this.label1.Text = "汉字";
// 
// label2
// 
this.label2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.Location = new System.Drawing.Point(0, 176);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(16, 40);
this.label2.TabIndex = 3;
this.label2.Text = "拼音";
// 
// listBox1
// 
this.listBox1.ImeMode = System.Windows.Forms.ImeMode.Katakana;
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(232, 176);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(64, 196);
this.listBox1.TabIndex = 4;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
// 
// Form1
// 
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(328, 222);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{


Program.genIndex(); listBox1.Hide(); //int PYcode=Program.getPYcode(textBox2.Text);           // if(PYcode != -1)
//textBox1.Text=Program.getHz(PYcode);
} private void textBox2_TextChanged(object sender, System.EventArgs e)
{

string buffer = " "; string text=""; buffer = textBox2.Text; if (buffer.Length == 0)
{
listBox1.Hide();
}
else if (buffer.Length != 0)
{
int pyCode = Program.getPYcode(buffer); if (pyCode >= 0 && pyCode <= 864)
{
text = Program.getHz(pyCode); if (text != "error!")
{
int Len = text.Length;
int x = Len / 10;
int y = Len % 10;
string[] str = new string[x + 1];
if (y == 0)
{
for (int i = 0; i < x; i++)
{
str[i] = text.Substring(10 * i, 10); }
}
else if (y != 0)
{
for (int i = 0; i < x; i++)
{
  str[i] = text.Substring(10 * i, 10);
}
str[x] = text.Substring(10 * x, y);
}
listBox1.Items.Clear(); for (int i = 0; i < str[0].Length; i++)
listBox1.Items.Add(i + ". " + str[0][i]); listBox1.Show();
}
}
} } private void textBox2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
      
if (e.KeyChar >= 48 && e.KeyChar <= 59)
{
               e.Handled=true;
switch (e.KeyChar)
{
case (char)48:  textBox1.Text = listBox1.Items[0].ToString().Substring(3, 1); break;
case (char)49:  textBox1.Text = listBox1.Items[1].ToString().Substring(3, 1); break;
case (char)50:  textBox1.Text = listBox1.Items[2].ToString().Substring(3, 1); break;
case (char)51:  textBox1.Text = listBox1.Items[3].ToString().Substring(3, 1); break;
case (char)52:  textBox1.Text = listBox1.Items[4].ToString().Substring(3, 1); break;
case (char)53:  textBox1.Text = listBox1.Items[5].ToString().Substring(3, 1); break;
case (char)54:  textBox1.Text = listBox1.Items[6].ToString().Substring(3, 1); break;
case (char)55:  textBox1.Text = listBox1.Items[7].ToString().Substring(3, 1); break;
case (char)56:  textBox1.Text = listBox1.Items[8].ToString().Substring(3, 1); break;
case (char)57:  textBox1.Text = listBox1.Items[9].ToString().Substring(3, 1); break;
}
                }
else if (e.KeyChar ==(char) Keys.Space)
{
               
//richTextBox1.AppendText(textBox1.Text);
textBox1.Clear();
listBox1.Hide();
textBox1.Focus();
}
            } private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{

}
}
}