Multi-pronged solution to the DOTNET framework full-angle Problem

Source: Internet
Author: User
Tags dotnet

Under the multi-pronged approach, the problem of dotNet FrameWork fullwidth is solved. When the information center of Lishui automotive transportation Group Co., Ltd., Ting Anting, uses C # To compile the winform program, the input method is often changed to fullwidth, it is inconvenient for user input. Microsoft has not solved this BUG so far. There are many discussions on the Internet, but it is still unsatisfactory. This article is based on the actual work situation, find a perfect solution. Solution 1: In the inheritance method, open VS2005, create a project, and add a Form named ImeForm. Because the API function is used, add reference in ImeForm: using System. runtime. interopServices; then declare the API functions related to the input method: # region declares some API functions [DllImport ("imm32.dll")] private static extern IntPtr ImmGetContext (IntPtr hwnd ); [DllImport ("imm32.dll")] private static extern bool ImmGetOpenStatus (IntPtr himc); [DllImport ("imm32.dll")] private static extern bool ImmSetOpenStatus (IntPtr himc, bool B ); [D LlImport ("imm32.dll")] private static extern bool ImmGetConversionStatus (IntPtr himc, ref int lpdw, ref int lpdw2); [DllImport ("imm32.dll")] private static extern int ImmSimulateHotKey (IntPtr hwnd, int lngHotkey); private const int IME_CMODE_FULLSHAPE = 0x8; private const int region = 0x11; # endregion defines a variable, to ensure that the related delegate is executed only once: private bool m_FirstStart = true; copy the following code: // <summary> /// When loading the window for the first time, set the events of each control, make it a halfwidth // </summary> // <param name = "e"> </param> protected override void OnLoad (EventArgs e) {base. onLoad (e); IntPtr HIme = ImmGetContext (this. handle); if (ImmGetOpenStatus (HIme) // if the input method is on {int iMode = 0; int iSentence = 0; bool bSuccess = ImmGetConversionStatus (HIme, ref iMode, ref iSentence); // retrieve the input method information if (bSuccess) {// if (iMode & IME_CMODE_FULLSHAPE)> 0) // if it is full ImmS ImulateHotKey (this. handle, role); // convert to halfwidth} if (m_FirstStart) {SetFormImeToHangul (this); m_FirstStart = false;} private void SetFormImeToHangul (Form p_Form) {foreach (System. windows. forms. control ctl in p_Form.Controls) {SetControlImeToHangul (ctl) ;}/// <summary> // recursive, traverse all controls in the current window /// </summary> /// <param name = "p_Control"> container </param> private void SetControlImeToHangu L (System. windows. forms. control p_Control) {if (p_Control.HasChildren) {foreach (Control ctl in p_Control.Controls) controls (ctl);} p_Control.KeyDown + = new controls (p_Control_KeyDown); p_Control.KeyPress + = new controls (p_Control_KeyPress ); p_Control.Enter + = new EventHandler (p_Control_Enter);} private void p_Control_KeyDown (object sender, KeyEventArgs e) {(sender Control). ImeMode = ImeMode. Hangul;} private void p_Control_KeyPress (object sender, KeyPressEventArgs e) {// prevents all possible corner int nIndex = "0123456789" in other cases .. ". IndexOf (e. keyChar); if (nIndex>-1) e. keyChar = "0123456789 .. "[nIndex];} private void p_Control_Enter (object sender, EventArgs e) {(sender as Control ). imeMode = ImeMode. hangul;} Finally, set the basic classes of all other windows to the default System. windows. foms. change Form to the ImeForm above and run the program again. Is the problem solved? Solution 2: If the class method already has a project, modifying the base class may cause problems. Therefore, you can write the method in solution 1 to a class, call SetFormImeToHangul (this); in the Load event.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.