当前位置:网站首页>C # switch between Chinese and English input methods
C # switch between Chinese and English input methods
2022-06-25 13:04:00 【Dotnet cross platform】
This article is authorized by the original author to share it twice in an original way , Welcome to reprint 、 Share .
Original author : Tang, song, yuan, Ming and Qing Dynasties
Original address :https://www.cnblogs.com/kybs0/p/10298697.html
C# Switch between Chinese and English input method
When entering in the interface , Sometimes it is necessary to restrict the input method .
Without customizing regular expressions or other input processing , Match the current language bar when switching between Chinese and English , There are several system schemes as follows :
InputLanguage programme
Use System.Windows.Forms.InputLanguage[1], Judge / Set the current ime state ;
Get the current input method
/// <summary>
/// Get the current input method
/// </summary>
/// <returns></returns>
private string GetCultureType()
{
var currentInputLanguage = InputLanguage.CurrentInputLanguage;
var cultureInfo = currentInputLanguage.Culture;
// Same as cultureInfo.IetfLanguageTag;
return cultureInfo.Name;
}Switch input method
/// <summary>
/// Switch input method
/// </summary>
/// <param name="cultureType"> Language item , Such as zh-CN,en-US</param>
private void SwitchToLanguageMode(string cultureType)
{
var installedInputLanguages = InputLanguage.InstalledInputLanguages;
if (installedInputLanguages.Cast<InputLanguage>().Any(i => i.Culture.Name == cultureType))
{
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(System.Globalization.CultureInfo.GetCultureInfo(cultureType));
CurrentLanguage = cultureType;
}
} adopt InputLanguage Set up , It can unify input methods in the same process . For example, after switching to English input method , The current program cycle has been in English input status .
InputMethod Additional attributes
System.Windows.Input.InputMethod,API The notes given in the original text are :
You can provide a framework for managing and using text Services , It provides alternate text , Such as the interactive functions supported by voice and handwriting input methods
1) InputMethod There are dependent properties under PreferredImeConversionMode, You can limit the input character type , At the same time, switch the Chinese and English status of the language bar .
This property sets the limit input character , The input method can be switched manually , Switch back to another input method .
2)InputMethod.IsInputMethodEnabled, You can also set the limit of Chinese and English input methods
Once set , The input method of the input control cannot be switched manually . Unless reset
IsInputMethodEnabledvalue .
InputMethod Suitable for the program cycle , Different input boxes have different input methods .
For example, the input method of the following two text boxes is limited :
// adopt InputMethod.PreferredImeConversionMode Additional attributes , Set the input method input conversion mode of the input box , That is, limit the input character type
InputMethod.SetPreferredImeConversionMode(InputTestTextBox0, ImeConversionModeValues.Alphanumeric);
InputMethod.SetPreferredImeConversionMode(InputTestTextBox1, ImeConversionModeValues.Native);ImeConversionModeValues The list of enumeration values is as follows :
/// <summary> Describes an input method input conversion mode to be performed .</summary>
[Flags]
public enum ImeConversionModeValues
{
/// <summary> The input method uses native characters ( Hiragana 、 Korean 、 Traditional Chinese ) Conversion mode .</summary>
Native = 1,
/// <summary> The input method uses Katakana conversion mode .</summary>
Katakana = 2,
/// <summary> The input method uses the Holomorphic transformation mode .</summary>
FullShape = 4,
/// <summary> The input method uses Roman character conversion mode .</summary>
Roman = 8,
/// <summary> The input method uses the character code conversion mode .</summary>
CharCode = 16, // 0x00000010
/// <summary> The input method does not perform any input conversion .</summary>
NoConversion = 32, // 0x00000020
/// <summary> Input method usage EUDC ( End user defined characters ) Conversion mode .</summary>
Eudc = 64, // 0x00000040
/// <summary> The input method uses the symbol conversion mode .</summary>
Symbol = 128, // 0x00000080
/// <summary> The input method uses a fixed conversion mode .</summary>
Fixed = 256, // 0x00000100
/// <summary> The input method uses alphanumeric conversion mode .</summary>
Alphanumeric = 512, // 0x00000200
/// <summary> The input method does not care which input conversion method is used ; The actual conversion method is uncertain .</summary>
DoNotCare = -2147483648, // -0x80000000
}Of the above two schemes Demo Source code [2]:
PS: If it is winform Program , It can be set directly Control.ImeMode attribute
Reference resources [3]
Reference material
[1]
System.Windows.Forms.InputLanguage: https://docs.microsoft.com/zh-cn/dotnet/api/system.windows.forms.inputlanguage?view=netframework-4.7.2
[2]Demo Source code : https://github.com/Kybs0/InputLanguageTestDemo
[3]Please refer to : https://blog.csdn.net/iluna/article/details/4903479
边栏推荐
猜你喜欢

2021-10-21

Parse JSON format data and save it to entity class

Baidu search stability analysis story
![[machine learning] parameter learning and gradient descent](/img/28/bb0a66b5f0702c995ca9cd7546b678.jpg)
[machine learning] parameter learning and gradient descent

【AI助力科研】loss曲线傻瓜式绘制

剑指 Offer 第 1 天栈与队列(简单)

Meichuang was selected into the list of "2022 CCIA top 50 Chinese network security competitiveness"

架构师需要具备的能力

Serevlt初识

Analyse de l'optimisation de la réécriture des requêtes lazyagg de l'entrepôt
随机推荐
3+1 guarantee: how is the stability of the highly available system refined?
WIN10环境下配置pytorch
Jenkins pipeline uses
坡道带来的困惑
Spoken English - weak reading
Jupyter Notebook主题字体设置及自动代码补全
list. replace, str.append
MySQL adds, modifies, and deletes table fields, field data types, and lengths (with various actual case statements)
CUDA error: unspecified launch failure
Summer Ending
Connect with the flight book and obtain the user information according to the userid
MySQL writes user-defined functions and stored procedure syntax (a detailed case is attached, and the problem has been solved: errors are reported when running user-defined functions, and errors are r
Differences between JS and JQ operation objects
深圳民太安智能二面_秋招第一份offer
时间过滤器(el-table)中使用
二叉树之_哈夫曼树_哈弗曼编码
AGCO AI frontier promotion (6.25)
剑指offer 第 3 天字符串(简单)
英语口语 - 弱读
Drawing cubes with Visio