新手学C#问下 两个textbox控件(txtbox1,txtbox2)  txtbox1用条码扫描枪来扫描一个数字切换到txtbox2 验证后焦点再返回txtbox1 怎么写 ,希望各位大神们帮帮忙!

解决方案 »

  1.   

    额 我的意思是从txtbox1 相当于回车下 到txtbox2 再回车下返回到txtbox这个过程怎么写
      

  2.   

    private   void   textBox1_KeyPress(object   sender,   System.Windows.Forms.KeyPressEventArgs   e) 

     if   (e.KeyChar   ==   (char)13) 

              textBox2.Focus(); 

    t1按回车焦点到t2
      

  3.   

    txtbox1.Focus();
    private   void   textBox2_KeyPress(object   sender,   System.Windows.Forms.KeyPressEventArgs   e) 

    if(e.KeyChar==(char)13) 

    txtbox1.Focus();


     
    或设置this.ActiveControl
      

  4.   

    4楼正解 其实还有一种方法 重写protected override void OnKeyPress(KeyPressEventArgs e)这个方法 具体里边怎么写一时不记得了
      

  5.   

    Form1_Load里设置this.KeyPreview = true; 
    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
    if (e.KeyCode == Keys.Enter && textBox1.Focused == true)
    {
    textBox2.Focused == true
    }
    if (e.KeyCode == Keys.Enter && textBox2.Focused == true)
    {
    textBox1.Focused == true
    }
    }
      

  6.   


    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)  
    {  
     if (e.KeyChar == (char)13)  
    {  
      textBox2.Focus();  
    }
    private void textBox2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)  
    {  
     if (e.KeyChar == (char)13)  
    {  
      textBox3.Focus();  
    }
    //以此类推即可