我用了9,但是不对啊!就是不知道原因,我用的是KeyPress
if(e.KeyChar==(char)9)
{
   if(textBox2.Text.Trim()=="")
     {
MessageBox.Show("请填写数量!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
         textBox2.Focus();
return;
      }
   if(textBox3.Text.Trim()=="")
      {
textBox3.Text="0";
      }
textBox4.Text=Convert.ToString(Convert.ToDecimal(textBox2.Text)*Convert.ToDecimal(textBox3.Text));
}
这里写上9就没有用啊!我想知道为什么?还是我的事件关联错了?

解决方案 »

  1.   

    Tab键是不会触发KeyPress事件的.
    如果你想在TextBos按下Tab触发事件,在Leave或LostFocus事件下写代码试试.
      

  2.   

    告诉你一个简单知道各个键值的方法private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
    MessageBox.Show(e.KeyValue.ToString(),"看看是多少?");//按下一个按钮.对话框里显示的就是这个剪的值
    //判断按下的按钮值,if(e.KeyValue==27)
    {
    this.Width=520;
    this.Height=428;
    }
    }
      

  3.   

    你不能单独用TAB,可以这样
    if ((e.KeyCode == Keys.Tab)&&(e.Control==true))
    {
    if(textBox2.Text.Trim()=="")
         {
    MessageBox.Show("请填写数量!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
             textBox2.Focus();
    return;
          }
       if(textBox3.Text.Trim()=="")
          {
    textBox3.Text="0";
          }
    textBox4.Text=Convert.ToString(Convert.ToDecimal(textBox2.Text)*Convert.ToDecimal(textBox3.Text));
    }