Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检测文本框c#keydown事件中输入的多个键?_C#_Silverlight_Keyboard - Fatal编程技术网

如何检测文本框c#keydown事件中输入的多个键?

如何检测文本框c#keydown事件中输入的多个键?,c#,silverlight,keyboard,C#,Silverlight,Keyboard,我想在silverlight中设计一个数字文本框 我已将文本框的按键事件添加到处理按键操作 在事件内部,我验证在文本框中输入的密钥 事件如下 private void TextBox_KeyDown(object sender, KeyEventArgs e) { if (!this.Validate(sender,e)) e.Handled = true; } 函数验证如下所示 private bool Validate(obj

我想在silverlight中设计一个数字文本框

我已将文本框的按键事件添加到处理按键操作

在事件内部,我验证在文本框中输入的密钥

事件如下

  private void TextBox_KeyDown(object sender, KeyEventArgs e)
    {
        if (!this.Validate(sender,e))
            e.Handled = true;
    }
函数验证如下所示

  private bool Validate(object sender, KeyEventArgs e)
    {

        if (e.Key == Key.Enter) //accept enter and tab
        {
            return true;
        }
        if (e.Key == Key.Tab)
        {
            return true;
        }

        if (e.Key < Key.D0 || e.Key > Key.D9) //accept number on alphnumeric key
            if (e.Key < Key.NumPad0 || e.Key > Key.NumPad9) //accept number fomr NumPad
                if (e.Key != Key.Back) //accept backspace
                    return false;

        return true;
    }
private bool验证(对象发送方,KeyEventArgs e)
{
if(e.Key==Key.Enter)//接受Enter和tab
{
返回true;
}
if(e.Key==Key.Tab)
{
返回true;
}
if(e.KeyKey.D9)//接受算术键上的数字
如果(e.KeyKey.NumPad9)//接受数字为mr NumPad
if(e.Key!=Key.Back)//接受退格
返回false;
返回true;
}
我无法检测换档和从0.D0键到1.D1键,即

SHIFT+1返回“

SHIFT+3像任何其他特殊键一样返回“#

我不希望用户在文本框中输入特殊字符


如何处理此按键事件???

e
应该有一个属性,告诉您是否按下了Shift、Control或Alt<代码>e。修饰符还可以为您提供有关已按下哪些其他修饰符键的其他信息


要取消字符,可以将
e.Handled
设置为
True
,这将导致控件忽略按键。

e
上应有一个属性,该属性将告诉您是否按下了Shift、control或Alt<代码>e。修饰符还可以为您提供有关已按下哪些其他修饰符键的其他信息

textBox2.Text = string.Empty;
textBox2.Text = e.Modifiers.ToString() + " + " + e.KeyCode.ToString();

要取消字符,可以将
e.Handled
设置为
True
,这将导致控件忽略按键。

在Silverlight中,我认为在
KeyEventArgs
类中没有任何
修饰符,而是在
键盘中:

textBox2.Text = string.Empty;
textBox2.Text = e.Modifiers.ToString() + " + " + e.KeyCode.ToString();
    public void KeyDown(KeyEventArgs e)
    {
        if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.D0)
        {
            ControlZero();
        }
    }

在Silverlight中,我认为在
KeyEventArgs
类中没有任何
修饰符,而是在
键盘中:

    public void KeyDown(KeyEventArgs e)
    {
        if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.D0)
        {
            ControlZero();
        }
    }

这是正确的答案。KeyEventArgs不包含修饰符。这是正确答案。KeyEventArgs不包含修饰符。