当前位置:网站首页>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
边栏推荐
- Optimization of lazyagg query rewriting in parsing data warehouse
- [visio] solving the fuzzy problem of parallelogram in word
- Elemtnui select control combined with tree control to realize user-defined search method
- 1251- Client does not support authentication protocol MySql错误解决方案
- 美创入选“2022 CCIA中国网络安全竞争力50强”榜单
- mysql导入导出数据到excel表日期出现问题
- 揭秘GaussDB(for Redis):全面对比Codis
- Sword finger offer 04 Find in 2D array
- 【AI助力科研】loss曲线傻瓜式绘制
- 又是被Visdom搞崩溃的一夜
猜你喜欢

Sword finger offer day 3 string (simple)

Online service emergency research methodology

CUDA error: unspecified launch failure
Module 5 (microblog comments)

How to implement a high-performance load balancing architecture?

更新pip&下载jupyter lab

Sword finger offer day 2 linked list (simple)

My first experience of go+ language -- a collection of notes on learning go+ design architecture

Fedora 35 部署DNS主从和分离解析 —— 筑梦之路

中国虚拟人哪家强?沙利文、IDC:小冰百度商汤位列第一梯队
随机推荐
Jenkins Pipeline使用
How to implement a high-performance load balancing architecture?
leetcode - 384. 打乱数组
Introduction to mongodb chapter 01 introduction to mongodb
Sword finger offer day 1 stack and queue (simple)
3+1 guarantee: how is the stability of the highly available system refined?
[转]以终为始,详细分析高考志愿该怎么填
[turn] starting from the end, analyze in detail how to fill in the college entrance examination volunteer
Command line garbled
Qt鼠标跟踪
2021-10-21
原生js---无限滚动
架构师需要具备的能力
二叉树之_哈夫曼树_哈弗曼编码
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
A half search method for sequential tables
Differences between JS and JQ operation objects
Elemtnui select control combined with tree control to realize user-defined search method
PPT绘论文图之导出分辨率
量化交易之回测篇 - 期货CTA策略实例(TQZFutureRenkoScalpingStrategy)