C#如何打開軟鍵盤

這篇文章主要介紹了C#如何打開軟鍵盤,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

10年積累的成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、成都外貿(mào)網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有淮南免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

注:程序是在VS2005里面,注意一下。控件需要自己添加了。一個(gè)ComboBox,一個(gè)Textbox,一個(gè)Button,直接拖進(jìn)去沒(méi)有更改name

用C#打開軟鍵盤程序開始

  1. using System;  

  2. using System.Collections.Generic;  

  3. using System.ComponentModel;  

  4. using System.Data;  

  5. using System.Drawing;  

  6. using System.Text;  

  7. using System.Windows.Forms;  

  8. using System.Runtime.InteropServices;  

  9.  

  10. namespace InputLanguageSwitch  

  11. {  

  12. /// <summary> 

  13. /// 獲取系統(tǒng)所有的輸入法,并可以程序改變當(dāng)前輸入法;打開關(guān)閉軟鍵盤。  

  14. /// 程序:房客  

  15. /// QQ:83849123  

  16. /// Blog:http://www.cnblogs.com/sxlfybb  

  17. /// </summary> 

  18. public partial class Form1 : Form  

  19. {  

  20. public Form1()  

  21. {  

  22. InitializeComponent();  

  23. this.InputLanguageChanged += new InputLanguageChangedEventHandler
    (Form1_InputLanguageChanged);  

  24. }  

  25.  

  26. void Form1_InputLanguageChanged(object sender, InputLanguageChangedEventArgs e)  

  27. {  

  28. //throw new Exception("The method or operation is not implemented.");  

  29. for( int i=0;i<comboBox1.Items.Count;i++)  

  30. {  

  31. if (InputLanguage.CurrentInputLanguage.LayoutName == comboBox1.Items[i].ToString())  

  32. {  

  33. comboBox1.SelectedIndex = i;  

  34. }  

  35.  

  36. }  

  37. }  

  38.  

  39. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)  

  40. {  

  41. string strTemp = comboBox1.Items[comboBox1.SelectedIndex].ToString();  

  42. InputLanguageCollection collects = InputLanguage.InstalledInputLanguages;  

  43. for (int i = 0; i < collects.Count; i++)  

  44. {  

  45. if (collects[i].LayoutName == strTemp)  

  46. InputLanguage.CurrentInputLanguage = collects[i];  

  47. }  

  48.  

  49. }  

  50.  

  51. private void Form1_Load(object sender, EventArgs e)  

  52. {  

  53. InputLanguageCollection collects = InputLanguage.InstalledInputLanguages;  

  54. for (int i = 0; i < collects.Count; i++)  

  55. {  

  56. comboBox1.Items.Add(collects[i].LayoutName);  

  57. }  

  58. comboBox1.SelectedIndex = collects.IndexOf(InputLanguage.CurrentInputLanguage);  

  59. }  

  60.  

  61. private void button1_Click(object sender, EventArgs e)  

  62. {  

  63. this.textBox1.Focus();  

  64. IntPtr hwndInput = ImmGetContext(this.Handle);  

  65. IntPtr dw1 = IntPtr.Zero;  

  66. IntPtr dw2 = IntPtr.Zero;  

  67. bool isSuccess = ImmGetConversionStatus(hwndInput, ref dw1, ref dw2);  

  68. if (isSuccess)  

  69. {  

  70. int intTemp = dw1.ToInt32() & IME_CMODE_SOFTKBD;  

  71. if (intTemp > 0)  

  72. dw1 = (IntPtr)(dw1.ToInt32() ^ IME_CMODE_SOFTKBD);  

  73. else  

  74. dw1 = (IntPtr)(dw1.ToInt32() IME_CMODE_SOFTKBD);  

  75. }  

  76. isSuccess = ImmSetConversionStatus(hwndInput, dw1, dw2);  

  77. ImmReleaseContext(this.Handle, hwndInput);  

  78. }  

  79.  

  80. public const int IME_CMODE_SOFTKBD = 0x80;  

  81.  

  82. [DllImport("imm32.dll", EntryPoint = "ImmGetContext")]  

  83. public static extern IntPtr ImmGetContext(  

  84. IntPtr hwnd  

  85. );  

  86. [DllImport("imm32.dll", EntryPoint = "ImmGetConversionStatus")]  

  87. public static extern bool ImmGetConversionStatus(  

  88. IntPtr himc,  

  89. ref IntPtr lpdw,  

  90. ref IntPtr lpdw2  

  91. );  

  92. [DllImport("imm32.dll", EntryPoint = "ImmSetConversionStatus")]  

  93. public static extern bool ImmSetConversionStatus(  

  94. IntPtr himc,  

  95. IntPtr dw1,  

  96. IntPtr dw2  

  97. );  

  98.  

  99. [DllImport("imm32.dll", EntryPoint = "ImmReleaseContext")]  

  100. public static extern int ImmReleaseContext(  

  101. IntPtr hwnd,  

  102. IntPtr himc  

  103. );  

  104.  

  105. }  

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“C#如何打開軟鍵盤”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!

網(wǎng)站題目:C#如何打開軟鍵盤
分享URL:http://muchs.cn/article2/ghspic.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站云服務(wù)器、用戶體驗(yàn)、小程序開發(fā)、Google、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)