/// <summary> turn on/off the input method editor /// </summary> /// <param name="control"> /// </param> public void controlIme(Control control, int imeMode) { if (control is TextBox || control is ComboBox || control is ListBox) { int hIMC = NativeWindowCommon.ImmGetContext(control.Handle); if (hIMC == 0) { return; } if (!isValid(imeMode)) { return; } if (control is TextBox) { if (imeMode == IME_DISABLE) { ((TextBox)control).ReadOnly = true; return; } } else { imeMode = 0; } int imeConvMode = imeMode2imeConvMode(imeMode); // get current open status bool isImeOpen = NativeWindowCommon.ImmGetOpenStatus(hIMC); if (!isImeOpen) { NativeWindowCommon.ImmSetOpenStatus(hIMC, true); } #if !PocketPC if (_prevImeState.IsContinue) #else if (_prevImeState.IsContinue || _prevImeMode.ConvMode == IME_NOT_INITIALIZED) #endif { _prevImeState.IsOpen = isImeOpen; // save the current open status as the previous state } _prevImeState.IsContinue = false; // get current conversion mode uint currImeConvMode; uint saveImeSentence; NativeWindowCommon.ImmGetConversionStatus(hIMC, out currImeConvMode, out saveImeSentence); if (_prevImeMode.IsContinue || _prevImeMode.ConvMode == IME_NOT_INITIALIZED) { _prevImeMode.ConvMode = (int)currImeConvMode; // save the current conversion mode as the previous state } _prevImeMode.IsContinue = false; if (imeConvMode == IME_CMODE_NOCONVERSION) { imeConvMode = _prevImeMode.ConvMode; if (imeMode == IME_FORCE_OFF || ImeAutoOff) { isImeOpen = false; #if !PocketPC _prevImeMode.IsContinue = true; // to save the conversion mode when the forcus is moved to other edit control #endif } else { isImeOpen = _prevImeState.IsOpen; _prevImeState.IsContinue = true; // to save the open status when the forcus is moved to other edit control _prevImeMode.IsContinue = true; // to save the conversion mode when the forcus is moved to other edit control } } else { isImeOpen = true; } #if PocketPC if (isImeOpen && (imeConvMode != currImeConvMode)) #else if (imeConvMode != currImeConvMode) #endif { NativeWindowCommon.ImmSetConversionStatus(hIMC, (uint)imeConvMode, saveImeSentence); } if (!isImeOpen) { #if PocketPC NativeWindowCommon.ImmSetConversionStatus(hIMC, (uint)IME_CMODE_NOCONVERSION, saveImeSentence); #endif NativeWindowCommon.ImmSetOpenStatus(hIMC, false); } NativeWindowCommon.ImmReleaseContext(control.Handle, hIMC); } }