自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C#控制輸入法詳細(xì)剖析

開發(fā) 后端
這里介紹為了C#控制輸入法,.NET類庫(kù)在System.Windows.Forms.InputLanguage類中提供了支持。我計(jì)劃先花一點(diǎn)時(shí)間講述InputLanguage類的功能,隨后舉一個(gè)實(shí)例InputLanguageRichEdit。

本文向大家介紹C#控制輸入法,可能好多人還不知道C#控制輸入法,沒(méi)有關(guān)系,看完本文你肯定有不少收獲,希望本文能教會(huì)你更多東西。

在Windows系統(tǒng)一般都安裝了至少三種輸入法,在輸入數(shù)據(jù)時(shí)常常會(huì)切換輸入法,雖然Windows系統(tǒng)提供了切換快捷健,但對(duì)輸入工作還是帶來(lái)了不少麻煩。如果在應(yīng)用程序中為用戶提供智能輸入法自動(dòng)切換,那么這樣的應(yīng)用程序就顯得更加專業(yè)、更加具有競(jìng)爭(zhēng)力。不知你可用過(guò)Access,在表數(shù)據(jù)輸入時(shí)Access自動(dòng)切換輸入法,很酷吧,現(xiàn)在你也可以實(shí)現(xiàn)這一切。如果也想你的程式也酷一下的話,請(qǐng)繼續(xù)...

為了C#控制輸入法,.NET類庫(kù)在System.Windows.Forms.InputLanguage類中提供了支持。我計(jì)劃先花一點(diǎn)時(shí)間講述InputLanguage類的功能,隨后舉一個(gè)實(shí)例InputLanguageRichEdit。

1、InputLanguage類是一個(gè)密封類,它提供了許多方法和屬性實(shí)現(xiàn)輸入法管理功能,這其中有幾個(gè)屬性尤其重要,我將在下面逐一講解,如果你想全面了解類的全部方法和屬性,請(qǐng)瀏覽MSDN。

  1. public static InputLanguage CurrentInputLanguage {get; set;}  
  2. //獲得或設(shè)置當(dāng)前線程的輸入法。  
  3.  
  4. public static InputLanguage DefaultInputLanguage {get;}  
  5. //獲得缺省輸入法。  
  6.  
  7. public static InputLanguageCollection InstalledInputLanguages{get;}  
  8. //獲得系統(tǒng)輸入法集??梢酝ㄟ^(guò)這個(gè)容器對(duì)象列舉系統(tǒng)當(dāng)前安裝的輸入法列表。  
  9.  
  10. public string LayoutName {get;}  
  11. //獲得輸入法在系統(tǒng)托盤中的注冊(cè)名稱。  
  12.  
  13. ......  

2、我們已經(jīng)研究了InputLanguage類提供的幾個(gè)重要屬性了,現(xiàn)在可以開始動(dòng)手在應(yīng)用開發(fā)中應(yīng)用InputLanguage類。我想創(chuàng)建一個(gè).NET Window Form的系統(tǒng)程序,用一個(gè)列表框列舉當(dāng)前系統(tǒng)安裝的所有輸入法,通過(guò)改變列表框的選項(xiàng)自動(dòng)改變當(dāng)前線程的輸入法。同時(shí)還實(shí)現(xiàn)了根據(jù)桌面托盤中C#控制輸入法的變化來(lái)改變列表框的選項(xiàng)。

(1)、新建項(xiàng)目 --> 選擇"Visual C#項(xiàng)目" --> 輸入項(xiàng)目名:InputLanguageRichEdit。

(2)、在"工具箱"中拖一個(gè)RichTextBox控件,命名為:richTextBox1;一個(gè)ComboBox控件,命名為:comboBox1;一個(gè)Button控件,命名為:But_Exit。

(3)、用下面的代碼代替

  1. private void InitializeComponent()。  
  2. {  
  3. this.comboBox1 = new System.Windows.Forms.ComboBox();  
  4. this.richTextBox1 = new System.Windows.Forms.RichTextBox();  
  5. this.But_Eixt = new System.Windows.Forms.Button();  
  6. this.SuspendLayout();  
  7. //  
  8. // comboBox1  
  9. //  
  10. this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;  
  11. this.comboBox1.DropDownWidth = 160;  
  12. this.comboBox1.Location = new System.Drawing.Point(8, 232);  
  13. this.comboBox1.Name = "comboBox1";  
  14. this.comboBox1.Size = new System.Drawing.Size(168, 20);  
  15. this.comboBox1.TabIndex = 1;  
  16. this.comboBox1.SelectedIndexChanged += new   System.EventHandler 
    (this.comboBox1_SelectedIndexChanged);  
  17. //  
  18. // richTextBox1  
  19. //  
  20. this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Top;  
  21. this.richTextBox1.Name = "richTextBox1";  
  22. this.richTextBox1.Size = new System.Drawing.Size(292, 208);  
  23. this.richTextBox1.TabIndex = 0;  
  24. this.richTextBox1.Text = "";  
  25. //  
  26. // But_Eixt  
  27. //  
  28. this.But_Eixt.Location = new System.Drawing.Point(200, 232);  
  29. this.But_Eixt.Name = "But_Eixt";  
  30. this.But_Eixt.TabIndex = 2;  
  31. this.But_Eixt.Text = "Eixt";  
  32. //  
  33. // Form1  
  34. //  
  35. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);  
  36. this.ClientSize = new System.Drawing.Size(292, 273);  
  37. this.Controls.AddRange(new System.Windows.Forms.Control[] {  
  38. this.But_Eixt,this.comboBox1,this.richTextBox1});  
  39. this.Name = "Form1";  
  40. this.Text = "Form1";  
  41. this.Load += new System.EventHandler(this.Form1_Load);  
  42. this.InputLanguageChanged += new   
  43. System.Windows.Forms.InputLanguageChangedEventHandler (this.ChangeInput);  
  44. this.ResumeLayout(false);  

(4)、插入下面代碼:

  1. private void Form1_Load(object sender, System.EventArgs e)  
  2. {  
  3. InputLanguageCollection ilc = InputLanguage.InstalledInputLanguages;  
  4. foreach ( InputLanguage il in ilc )  
  5. {  
  6. comboBox1.Items.Add( il.LayoutName );  
  7. }  
  8. comboBox1.SelectedIndex = InputLanguage.InstalledInputLanguages.IndexOf 
    ( InputLanguage.CurrentInputLanguage ) ;  
  9. }  
  10. private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)  
  11. {  
  12. InputLanguage il = InputLanguage.
    InstalledInputLanguages[ comboBox1.SelectedIndex ];  
  13. InputLanguage.CurrentInputLanguage = il;  
  14. }  
  15. private void ChangeInput(object sender, 
    System.Windows.Forms.InputLanguageChangedEventArgs e)  
  16. {  
  17. InputLanguage il = e.InputLanguage ;  
  18. int i = InputLanguage.InstalledInputLanguages.IndexOf( il );  
  19. if( i >= 0 && i < InputLanguage.InstalledInputLanguages.Count )  
  20. {  
  21. comboBox1.SelectedIndex = i ;  
  22. }  
  23. }  
  24. private void But_Eixt_Click(object sender, System.EventArgs e)  
  25. {  
  26. Application.Exit();  
  27. }  

【編輯推薦】

  1. C#窗體里調(diào)用淺談
  2. C#調(diào)用ListEmployee命令
  3. C# CreateEmployeeDefinition()函數(shù)
  4. C#實(shí)現(xiàn)斷點(diǎn)續(xù)傳詳細(xì)剖析
  5. C# Employee對(duì)象淺談
責(zé)任編輯:佚名 來(lái)源: 博客園
相關(guān)推薦

2009-08-27 17:14:36

C# Socket

2009-09-11 11:17:04

C#引用類型

2009-09-18 10:00:17

C#數(shù)組操作

2009-08-31 17:26:32

C#異常處理

2009-09-03 16:58:49

C#內(nèi)存管理

2009-08-27 17:51:34

C#匿名方法

2021-08-04 16:36:00

Windows 10Windows微軟

2021-11-11 23:00:50

Windows 10Windows微軟

2009-09-04 11:06:40

C#訪問(wèn)修飾符

2009-09-07 13:42:56

C# Pop3類

2009-08-28 15:38:49

C#實(shí)現(xiàn)斷點(diǎn)續(xù)傳

2021-10-15 22:17:08

Windows 10Windows微軟

2021-04-20 08:30:23

微信微信輸入法張小龍

2011-09-15 09:34:48

ubuntu輸入法

2010-01-08 16:50:51

Ubuntu SCIM

2010-06-08 18:50:30

OpenSUSE 輸入

2010-01-11 10:09:14

Ubuntulinux輸入法設(shè)置

2012-02-15 11:14:21

搜狗輸入法

2021-11-06 23:04:10

Windows 10Windows微軟

2023-09-09 07:08:37

百度輸入法AI
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)