//编码文本框的回车事件
        private void txtCode_KeyUp(object sender, KeyEventArgs e)
        {
        
            if (e.KeyCode == Keys.Enter&&enter==0)
            {
                DataRow[] drs = dttory.Select("cInvcode='" + txtCode.Text + "' or cbarcode='"+txtCode.Text+"' ");
                if (drs.Length > 0)
                {
                    cinvcode = drs[0]["cinvcode"].ToString();
                    txtName.Text = drs[0]["cinvname"].ToString();
                    txtNum.Text = "1";
                    txtPice.Text = drs[0]["iinvlscost"].ToString();//fretailprice
                    minpice = drs[0]["iinvlscost"].ToString();
                    igrouptype = drs[0]["igrouptype"].ToString();
                    bservice = drs[0]["bservice"].ToString();                 
                    itaxrate = Decimal.Parse(drs[0]["itaxrate"].ToString());
                    if (txtPice.Text.Length > 0)
                    {
                        txtMoney.Text =Decimal.Round((decimal.Parse(txtNum.Text) * decimal.Parse(txtPice.Text)),2).ToString();                    }
                    else
                    {
                        txtMoney.Text = "0";
                    }                    txtName.Enabled = true;
                    txtNum.Enabled = true;
                    txtPice.Enabled = true;
                    txtNum.Focus();
                }
                else
                {                   
                    MessageBox.Show("此编码对应的商品不存在");
                }
            }
        }如代码,通过触发文本框的 txtCode_KeyUp事件进行处理。当MessageBox.Show的时候,会出现一个提示框,上面有确定按钮。要求回车的似乎对话框关闭。但是同事不触发再一次的文本框回车事件。
现在的情况是一旦 出现提示框,接连着按回车会一直重复这个动作。。求帮助。。
必须满足要求。。
很纠结的一个问题。

解决方案 »

  1.   

    用DialogResult变量接收MessageBox.Show("此编码对应的商品不存在");,每次keyup的时候,判断一下这个值是否为空。
      

  2.   

    也可以从提示框入手,用lable显示提示消息。避免这样“纠集”的问题。
      

  3.   

     if (e.KeyCode == Keys.Enter&&enter==0)           
     { 
         ...
         if (drs.Length > 0)  
         {  
              ...                 
         }       
         else   
         {
             enter = true;  //先置状态再弹
               MessageBox.Show("此编码对应的商品不存在");                
         }            
    }
      

  4.   


    bool canEnter = true;
    private void txtCode_KeyUp(object sender, KeyEventArgs e)
    {
        if (!canEnter) { canEnter = true; return; }
        if (e.KeyCode == Keys.Enter&&enter==0)
        {
            DataRow[] drs = dttory.Select("cInvcode='" + txtCode.Text + "' or cbarcode='"+txtCode.Text+"' ");
            if (drs.Length > 0)
            {
                cinvcode = drs[0]["cinvcode"].ToString();
                txtName.Text = drs[0]["cinvname"].ToString();
                txtNum.Text = "1";
                txtPice.Text = drs[0]["iinvlscost"].ToString();//fretailprice
                minpice = drs[0]["iinvlscost"].ToString();
                igrouptype = drs[0]["igrouptype"].ToString();
                bservice = drs[0]["bservice"].ToString();                 
                itaxrate = Decimal.Parse(drs[0]["itaxrate"].ToString());
                if (txtPice.Text.Length > 0)
                {
                    txtMoney.Text =Decimal.Round((decimal.Parse(txtNum.Text) * decimal.Parse(txtPice.Text)),2).ToString();
                }
                else
                {
                    txtMoney.Text = "0";
                }
                txtName.Enabled = true;
                txtNum.Enabled = true;
                txtPice.Enabled = true;
                txtNum.Focus();
            }
            else
            {                   
                MessageBox.Show("此编码对应的商品不存在");
                canEnter = false;
            }
        }
    }LZ试试