当前位置:网站首页>C#切换输入法
C#切换输入法
2022-08-03 05:27:00 【谷凯Jump】
有时候程序运行时,需要自动切换到英文输入状态,可通过代码进行控制输入法。
C#
static void Main(string[] args)
{
Console.WriteLine(GetCultureType());
SwitchToLanguageMode("en-US");
Console.WriteLine(GetCultureType());
Console.ReadLine();
}
/// <summary>
/// 切换输入法
/// </summary>
/// <param name="cultureType">语言项,如zh-CN,en-US</param>
private static 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;
}
}
/// <summary>
/// 获取当前输入法
/// </summary>
/// <returns></returns>
private static string GetCultureType()
{
var currentInputLanguage = InputLanguage.CurrentInputLanguage;
var cultureInfo = currentInputLanguage.Culture;
//同 cultureInfo.IetfLanguageTag;
return cultureInfo.Name;
}
VB.net
''' <summary>
''' 切换输入法
''' </summary>
''' <param name="cultureType">语言项,如zh-CN,en-US</param>
Public Sub SwitchToLanguageMode(ByVal cultureType As String)
Dim installedInputLanguages = InputLanguage.InstalledInputLanguages
For Each language As InputLanguage In InputLanguage.InstalledInputLanguages
If language.Culture.Name = cultureType Then
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(System.Globalization.CultureInfo.GetCultureInfo(cultureType))
Exit For
End If
Next
End Sub
''' <summary>
''' 获取当前输入法
''' </summary>
''' <returns></returns>
Public Function GetCultureType() As String
Dim currentInputLanguage = InputLanguage.CurrentInputLanguage
Dim cultureInfo = currentInputLanguage.Culture
Return cultureInfo.Name
End Function
边栏推荐
猜你喜欢
随机推荐
零基础小白想往游戏建模方向发展,3D游戏建模好学嘛?
数组与字符串10-实现 strStr()
ZEMAX | 探索 OpticStudio中的序列模式
宝塔负载均衡配置及nfs共享
数组与字符串12-数组拆分
嘿!selenium自动下载driver版本,得知道一下
二分查找6 - 寻找峰值
pandoc -crossref插件实现markdwon文档转word后公式编号自定义
MySql【后面附有练习题】
Practice of MySql's Sql statement (try how many you can write)
树——前序
3D建模:做什么副业在家就能月入1W?
【3D建模制作技巧分享】ZBrush快捷键如何设置
5. What is the difference between int and Integer?
Delightful Nuxt3 Tutorial (2): Build a Blog Quickly and Easily
大佬!Maya+ZBrush+Substance制作泰坦野兽全流程!
采用Trench肖特基二极管,实现功率密度的显著提升
【C语言】二分查找
【面筋1】一些没什么标准答案的问题
3. What is the difference between final, finally, and finalize?