当前位置:网站首页>C # to switch input method
C # to switch input method
2022-08-03 06:34:00 【Gu Kai Jump】
Sometimes when the program is running, it needs to automatically switch to the English input state, and the input method can be controlled by code.
C#
static void Main(string[] args){Console.WriteLine(GetCultureType());SwitchToLanguageMode("en-US");Console.WriteLine(GetCultureType());Console.ReadLine();}/// /// Switch input method/// /// language item, such as zh-CN, en-USprivate static void SwitchToLanguageMode(string cultureType){var installedInputLanguages = InputLanguage.InstalledInputLanguages;if (installedInputLanguages.Cast().Any(i => i.Culture.Name == cultureType)){InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(System.Globalization.CultureInfo.GetCultureInfo(cultureType));//CurrentLanguage = cultureType;}}/// /// Get the current input method/// /// private static string GetCultureType(){var currentInputLanguage = InputLanguage.CurrentInputLanguage;var cultureInfo = currentInputLanguage.Culture;//same as cultureInfo.IetfLanguageTag;return cultureInfo.Name;}
VB.net
''' ''' switch input method''' ''' language item, such as zh-CN, en-USPublic Sub SwitchToLanguageMode(ByVal cultureType As String)Dim installedInputLanguages = InputLanguage.InstalledInputLanguagesFor Each language As InputLanguage In InputLanguage.InstalledInputLanguagesIf language.Culture.Name = cultureType ThenInputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(System.Globalization.CultureInfo.GetCultureInfo(cultureType))Exit ForEnd IfNextEnd Sub''' ''' Get the current input method''' ''' Public Function GetCultureType() As StringDim currentInputLanguage = InputLanguage.CurrentInputLanguageDim cultureInfo = currentInputLanguage.CultureReturn cultureInfo.NameEnd Function
边栏推荐
猜你喜欢
随机推荐
宝塔负载均衡配置及nfs共享
./autogen.sh: 4: ./autogen.sh: autoreconf: not found
JS--正则表达式
在Maya和ZBrush中制作战士模型
ue4学习日记2(项目迁移,画刷,附材质)
学习C的第一天,尝试一下写博客
二、Exception和Error有什么区别?
移动端人脸风格化技术的应用
【随笔】我为啥想写无关紧要的随笔?
802.1AS的BMCA(最佳主时钟选举)理解
在OracleLinux8.6的Zabbix6.0中监控Oracle11gR2
Practice of MySql's Sql statement (try how many you can write)
g++ parameter description
Difference between @JsonProperty and JSONField?
数组与字符串14-使用双指针移除元素
2021-06-14
ARP协议及简单路由器原理(1)
界面仅允许扫码枪录入禁止手工键盘输入
classpath: comparison with classpath*
appium(3)webview测试