20111228_给窗体设置默认输入法

//给窗体设置默认输入法

//新建一个窗体类ImeForm,设置Form1:ImeForm

public class ImeForm:System.Windows.Forms.Form
{
[DllImport("imm32.dll")]
public static extern IntPtr ImmGetContext(IntPtr hWnd);
[DllImport("imm32.dll")]
public static extern bool ImmGetConversionStatus(IntPtr hIMC,ref int conversion, ref int sentence);
[DllImport("imm32.dll")]
public static extern bool ImmSetConversionStatus(IntPtr hIMC, int conversion, int sentence);

//重载Form的OnActivated
protected override void OnActivated(EventArgs e)
{
foreach (InputLanguage iL in InputLanguage.InstalledInputLanguages)
{
if (iL.LayoutName.Contains("搜狗拼音输入法"))
{
InputLanguage.CurrentInputLanguage = iL;
break;
}
if (iL.LayoutName.Contains("智能 ABC"))
{
InputLanguage.CurrentInputLanguage = iL;
break;
}
}
IntPtr prt = ImmGetContext(this.Handle);
int iMode = 1;
int iSentence = 0;
if (!ImmSetConversionStatus(prt, iMode, iSentence))
{
//MessageBox.Show("change error");
}
}
}

 

还有设置半角输入法:

this.ImeMode = ImeMode.OnHalf;  //写在Page_load中

你可能感兴趣的:(输入法)