在C#应用程序中控制输入法
http://tech.ddvip.com 2006年08月01日 社区交流
本文详细介绍在C#应用程序中控制输入法
(1)、新建项目 --> 选择"Visual C#项目" --> 输入项目名:InputLanguageRichEdit。
(2)、在"工具箱"中拖一个RichTextBox控件,命名为:richTextBox1;一个ComboBox控件,命名为:comboBox1;一个Button控件,命名为:But_Exit。
(3)、用下面的代码代替private void InitializeComponent()。
{(4)、插入下面代码:
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.But_Eixt = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.DropDownWidth = 160;
this.comboBox1.Location = new System.Drawing.Point(8, 232);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(168, 20);
this.comboBox1.TabIndex = 1;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// richTextBox1
//
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(292, 208);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// But_Eixt
//
this.But_Eixt.Location = new System.Drawing.Point(200, 232);
this.But_Eixt.Name = "But_Eixt";
this.But_Eixt.TabIndex = 2;
this.But_Eixt.Text = "Eixt";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.But_Eixt,this.comboBox1,this.richTextBox1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.InputLanguageChanged += new System.Windows.Forms.InputLanguageChangedEventHandler(this.ChangeInput);
this.ResumeLayout(false);
}
private void Form1_Load(object sender, System.EventArgs e)
{
InputLanguageCollection ilc = InputLanguage.InstalledInputLanguages;
foreach ( InputLanguage il in ilc )
{
comboBox1.Items.Add( il.LayoutName );
}
comboBox1.SelectedIndex = InputLanguage.InstalledInputLanguages.IndexOf( InputLanguage.CurrentInputLanguage ) ;
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
InputLanguage il = InputLanguage.InstalledInputLanguages[ comboBox1.SelectedIndex ];
InputLanguage.CurrentInputLanguage = il;
}
private void ChangeInput(object sender, System.Windows.Forms.InputLanguageChangedEventArgs e)
{
InputLanguage il = e.InputLanguage ;
int i = InputLanguage.InstalledInputLanguages.IndexOf( il );
if( i >= 0 && i < InputLanguage.InstalledInputLanguages.Count )
{
comboBox1.SelectedIndex = i ;
}
}
private void But_Eixt_Click(object sender, System.EventArgs e)
{
Application.Exit();
}

来源:yesky 作者:周毅 责编:豆豆技术应用