Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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# 4.0 textbox为输入的每个数字发送enter键_C# 4.0 - Fatal编程技术网

C# 4.0 textbox为输入的每个数字发送enter键

C# 4.0 textbox为输入的每个数字发送enter键,c#-4.0,C# 4.0,我用一个文本框接受条形码输入,然后按enter键处理输入。但它会为输入的每个数字发送一次enter键。有没有办法只发送一次enter键?或者是压制对方进入 private void txtBscanned_KeyDown(object sender, KeyEventArgs e) { this.txtBscanned.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OnKeyDownHandler);

我用一个文本框接受条形码输入,然后按enter键处理输入。但它会为输入的每个数字发送一次enter键。有没有办法只发送一次enter键?或者是压制对方进入

private void txtBscanned_KeyDown(object sender, KeyEventArgs e)
    {
       this.txtBscanned.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OnKeyDownHandler);
    }
   private void OnKeyDownHandler(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {

                MessageBox.Show(txtBscanned.Text);
        }
    }

为什么要在文本框本身上指定一个keydown事件?您应该在构造函数上或使用设计器分配事件

    public Form1()
    {
        InitializeComponent();
        txtBscanned.KeyDown += new KeyEventHandler(this.OnKeyDownHandler);
      }

什么会触发你所说的“一次”呢?我输入13个数字,然后在最后输入。但是messagebox出现了13次。谢谢你修复了它。如果它修复了你的问题,请将其标记为答案