[英]C# use different keyboard layout in different text boxes automatically?
I would like to have three textboxes for user input, but for each textbox I would like a different keyboard layout to be used while entering text (without the need to manually change the kayboard layout). 我想有三个用于用户输入的文本框,但是对于每个文本框,我希望在输入文本时使用不同的键盘布局(无需手动更改kayboard布局)。
In textxbox 1 I would like my normal (swedish) keyboard layout to be used while I write. 在textxbox 1中,我想在我写的时候使用我的普通(瑞典语)键盘布局。 In the second I would like to have Japanese Hiragana layout.
在第二个我想有日本平假名布局。 And in the third I would like too have Japanese Katakana layout.
在第三个我想也有日本片假名布局。
Is it possible to do? 有可能吗?
As it is now I must manually change the keyboard layout with Windowskey+Space (this cycles through all keyboard layouts). 就像现在一样,我必须使用Windowskey + Space手动更改键盘布局(这会循环显示所有键盘布局)。
Hope this works for you: 希望这对你有用:
private void textBox1_Enter(object sender, EventArgs e)
{
// Get index of current Input Language
int currentLang = InputLanguage.InstalledInputLanguages.IndexOf(InputLanguage.CurrentInputLanguage);
// Calculate next Input Language
InputLanguage nextLang = ++currentLang == InputLanguage.InstalledInputLanguages.Count ? InputLanguage.InstalledInputLanguages[0] : InputLanguage.InstalledInputLanguages[currentLang];
// Change current Language to the calculated:
ChangeInputLanguage(nextLang);
}
public void ChangeInputLanguage(InputLanguage InputLang)
{
// Check is this Language really installed. Raise exception to warn if it is not:
if (InputLanguage.InstalledInputLanguages.IndexOf(InputLang) == -1)
throw new ArgumentOutOfRangeException();
// InputLAnguage changes here:
InputLanguage.CurrentInputLanguage = InputLang;
}
Here is the reference link - Change Input Language programmatically? 以下是参考链接 - 以编程方式更改输入语言?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.