這篇文章主要介紹了C#如何打開(kāi)軟鍵盤(pán),具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
10年積累的成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、成都外貿(mào)網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶(hù)對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶(hù)得到更好、更有力的網(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#打開(kāi)軟鍵盤(pán)程序開(kāi)始
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace InputLanguageSwitch
{
///
/// 獲取系統(tǒng)所有的輸入法,并可以程序改變當(dāng)前輸入法;打開(kāi)關(guān)閉軟鍵盤(pán)。
/// 程序:房客
/// QQ:83849123
/// Blog:http://www.cnblogs.com/sxlfybb
///
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.InputLanguageChanged += new InputLanguageChangedEventHandler
(Form1_InputLanguageChanged);}
void Form1_InputLanguageChanged(object sender, InputLanguageChangedEventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
for( int i=0;i
;i++) {
if (InputLanguage.CurrentInputLanguage.LayoutName == comboBox1.Items[i].ToString())
{
comboBox1.SelectedIndex = i;
}
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string strTemp = comboBox1.Items[comboBox1.SelectedIndex].ToString();
InputLanguageCollection collects = InputLanguage.InstalledInputLanguages;
for (int i = 0; i < collects.Count; i++)
{
if (collects[i].LayoutName == strTemp)
InputLanguage.CurrentInputLanguage = collects[i];
}
}
private void Form1_Load(object sender, EventArgs e)
{
InputLanguageCollection collects = InputLanguage.InstalledInputLanguages;
for (int i = 0; i < collects.Count; i++)
{
comboBox1.Items.Add(collects[i].LayoutName);
}
comboBox1.SelectedIndex = collects.IndexOf(InputLanguage.CurrentInputLanguage);
}
private void button1_Click(object sender, EventArgs e)
{
this.textBox1.Focus();
IntPtr hwndInput = ImmGetContext(this.Handle);
IntPtr dw1 = IntPtr.Zero;
IntPtr dw2 = IntPtr.Zero;
bool isSuccess = ImmGetConversionStatus(hwndInput, ref dw1, ref dw2);
if (isSuccess)
{
int intTemp = dw1.ToInt32() & IME_CMODE_SOFTKBD;
if (intTemp > 0)
dw1 = (IntPtr)(dw1.ToInt32() ^ IME_CMODE_SOFTKBD);
else
dw1 = (IntPtr)(dw1.ToInt32() IME_CMODE_SOFTKBD);
}
isSuccess = ImmSetConversionStatus(hwndInput, dw1, dw2);
ImmReleaseContext(this.Handle, hwndInput);
}
public const int IME_CMODE_SOFTKBD = 0x80;
[DllImport("imm32.dll", EntryPoint = "ImmGetContext")]
public static extern IntPtr ImmGetContext(
IntPtr hwnd
);
[DllImport("imm32.dll", EntryPoint = "ImmGetConversionStatus")]
public static extern bool ImmGetConversionStatus(
IntPtr himc,
ref IntPtr lpdw,
ref IntPtr lpdw2
);
[DllImport("imm32.dll", EntryPoint = "ImmSetConversionStatus")]
public static extern bool ImmSetConversionStatus(
IntPtr himc,
IntPtr dw1,
IntPtr dw2
);
[DllImport("imm32.dll", EntryPoint = "ImmReleaseContext")]
public static extern int ImmReleaseContext(
IntPtr hwnd,
IntPtr himc
);
}
}
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“C#如何打開(kāi)軟鍵盤(pán)”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!