在 C# 中更改密钥
Change key in c#
我需要在 c# 中更改密钥。
示例:如果按 "a" 然后按 "b"。
像这样:
Key.change("a","b"); // a = key , b = value
请注意:键是静态的,值是动态的,意思是:键=(始终)"a",值=(可以更改)"b" || "c" || "d",等等
所以,如果这个问题能以简单的方式解决,我真的很高兴。
谢谢,抱歉英语不好。
在表单 class 上,添加此方法和变量:
char change = 'b';
private void ChangeKey(object sender, KeyPressEventArgs e)
{
if (e.KeyChar=='a')
{
e.KeyChar = change;
}
}
然后在 Load 或 Form 构造函数上,手动订阅您拥有的每个输入控件
textBox1.KeyPress += ChangeKey;
textBox2.KeyPress += ChangeKey;
或全部
foreach (var item in Controls.OfType<Control>())
{
item.KeyPress += ChangeKey;
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar > (char)001 )
{
e.KeyChar++;
}
}
也有效。
我需要在 c# 中更改密钥。
示例:如果按 "a" 然后按 "b"。
像这样:
Key.change("a","b"); // a = key , b = value
请注意:键是静态的,值是动态的,意思是:键=(始终)"a",值=(可以更改)"b" || "c" || "d",等等
所以,如果这个问题能以简单的方式解决,我真的很高兴。
谢谢,抱歉英语不好。
在表单 class 上,添加此方法和变量:
char change = 'b';
private void ChangeKey(object sender, KeyPressEventArgs e)
{
if (e.KeyChar=='a')
{
e.KeyChar = change;
}
}
然后在 Load 或 Form 构造函数上,手动订阅您拥有的每个输入控件
textBox1.KeyPress += ChangeKey;
textBox2.KeyPress += ChangeKey;
或全部
foreach (var item in Controls.OfType<Control>())
{
item.KeyPress += ChangeKey;
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar > (char)001 )
{
e.KeyChar++;
}
}
也有效。