To control the input method in a C # application

Source: Internet
Author: User

In the Windows system is generally installed with at least three input methods, in the input data often switch input method, although the Windows system provides a switch shortcut, but the input work has brought a lot of trouble. If the user is provided with an intelligent input method for automatic switching in the application, such applications will become more professional and competitive. I do not know you can access, in the form of data entry when Access automatically switch input method, it is cool, now you can also achieve this. If you also want to cool your program, please continue ...

In order to control the input method,. NET class Library provides support in the System.Windows.Forms.InputLanguage class. I plan to take a moment to talk about the functionality of the InputLanguage class, and then give an example of Inputlanguagerichedit.

1, InputLanguage class is a sealed class, it provides a number of methods and properties to implement input method management functions, which have several attributes are particularly important, I will explain the following, if you want to fully understand all the methods and properties of the class, please browse MSDN.

public static InputLanguage CurrentInputLanguage {get; set;}
//获得或设置当前线程的输入法。
public static InputLanguage DefaultInputLanguage {get;}
//获得缺省输入法。
public static InputLanguageCollection InstalledInputLanguages{get;}
//获得系统输入法集。可以通过这个容器对象列举系统当前安装的输入法列表。
public string LayoutName {get;}
//获得输入法在系统托盘中的注册名称。
......
2, we have studied the InputLanguage class provides several important attributes, now can begin to apply the InputLanguage class in the application development. I want to create a system program for the. NET Window form, enumerate all the input methods installed by the current system with a list box, and automatically change the input method of the current thread by changing the option of the list box. It also implements the option of changing the list box according to the changes in the input method in the desktop tray.

(1), New project--> select Visual C # project--> Enter the project name: Inputlanguagerichedit.

(2), in the Toolbox, drag a RichTextBox control, named: RichTextBox1; a combobox control named: ComboBox1; a button control named: But_exit.

(3) Replace the private void InitializeComponent () with the following code.

{
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);
}
(4), insert the following code:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.