|
■No95812 (sck さん) に返信 > この切り替えを、VB.NET から行うにはどうすればいいでしょうか? 投稿分類が VB.NET ではなく .NET 全般になっていたので、 一応、VB / C# 両方載せておきます。
Private Function ChangeInputLanguage(layoutName As String) As Boolean Dim languages = InputLanguage.InstalledInputLanguages.OfType(Of InputLanguage)() Dim language = languages.FirstOrDefault(Function(c) c.LayoutName = layoutName) If language IsNot Nothing Then InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(language.Culture) Return True Else Return False End If End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click, Button2.Click ChangeInputLanguage("US") End Sub
private void button1_Click(object sender, EventArgs e) { ChangeInputLanguage(1033); } private void button2_Click(object sender, EventArgs e) { ChangeInputLanguage(1041); }
private bool ChangeInputLanguage(int lcid) { var culture = InputLanguage.InstalledInputLanguages.OfType<InputLanguage>() .FirstOrDefault(x => x.Culture?.LCID == lcid)?.Culture; if (culture == null) { return false; } else { InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(culture); return true; } }
|