日期:2014-05-18 浏览次数:20749 次
using System.Runtime.InteropServices; [DllImport("imm32.dll")] public static extern IntPtr ImmGetContext(IntPtr hWnd); [DllImport("imm32.dll")] public static extern bool ImmGetOpenStatus(IntPtr hIMC); [DllImport("imm32.dll")] public static extern bool ImmGetConversionStatus(IntPtr hIMC, ref int conversion, ref int sentence); [DllImport("imm32.dll")] public static extern bool ImmReleaseContext(IntPtr hWnd, IntPtr hIMC); [DllImport("imm32.dll")] public static extern bool ImmSetConversionStatus(IntPtr hIMC, int conversion, int sentence); const int IME_CMODE_FULLSHAPE = 0x0008; public static void SetHalfShape(IntPtr AHandle) { IntPtr vIme = ImmGetContext(AHandle); if (ImmGetOpenStatus(vIme)) // 输入法是打开的 { int vMode = 0, vSentence = 0; if (ImmGetConversionStatus(vIme, ref vMode, ref vSentence)) // 获取输入法状态 { if ((vMode & IME_CMODE_FULLSHAPE) > 0) // 是全角 { vMode &= (~IME_CMODE_FULLSHAPE); ImmSetConversionStatus(vIme, vMode, vSentence); } } } ImmReleaseContext(AHandle, vIme); } private void textBox1_Enter(object sender, EventArgs e) // 设置焦点的时候 { SetHalfShape(((TextBox)sender).Handle); }
------解决方案--------------------
安装.NET 2.0的一个补丁
------解决方案--------------------
你可以把一楼的方法做成一个控件,在父窗体上添加这个控件,在子窗体上作一下设置就可以了.