我正在开发基于Windows Presentation Foundation(WPF)的代码编辑器。当用户添加一个打开的brakcet时,我想自动添加关闭括号。但在System.Windows.Input.Key
,我找不到括号的键码。我还需要在代码部分中提到下面提到的一些字符代码。
// Brackets, square brackets and curly brackets "(" ")" "[" "]" "{" "}"
// Lower/Greater: "<" ">"
// Equal, quote and single quote " ' =
private void htmlcode_KeyDown(object sender, KeyEventArgs e)
{
if(e.Key=<the keycode that I need>)
{
htmlcode.Text=htmlcode.Text+"<close variant of key>";
}
}
我需要System.Windows.Input.Key
枚举中这些字符的名称。
System.Windows.Input.Key
枚举没有这些字符的值。
但是你可以处理PreviewTextInput
事件而不是KeyDown
:
private void htmlcode_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
switch (e.Text)
{
case "{":
// add "}"
break;
// etc
}
}