呵呵,你没有清空text
private void txtRight_KeyPress(object sender, KeyPressEventArgs e)
        {
            
                string strA = "";
                strA = txtRight.Text;
                if (strA == "a" || strA == "b" || strA == "c" || strA == "d")
                {
                    string s=strA.ToUpper();
                    txtRight.Text ="";
                    txtRight.Text = s;
                }            }
  }

解决方案 »

  1.   

    试了一下,楼主的代码是可以的啊
    string strA = "";
    strA = TextBox1.Text;
    if (strA == "a" || strA == "b" || strA == "c" || strA == "d")
    {
    string s=strA.ToUpper();
    TextBox1.Text = s;
    }
    不知道楼主是不是将abcd同时弄进去了,哈哈
      

  2.   

    和清空没关系
    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if (e.KeyChar == 'a' || e.KeyChar == 'b'|| e.KeyChar == 'c' || e.KeyChar == 'd')
    {
    textBox1.Text = e.KeyChar.ToString().ToUpper();
                     // textBox1.Text += e.KeyChar.ToString().ToUpper();
    }
    e.Handled=true;
    }
      

  3.   

    e.Handled=true;
    ----------------
    这是什么意思,学习学习
      

  4.   

    private void txtRight_KeyPress(object sender, KeyPressEventArgs e)
            {
                
                    string strA = "";
                    strA = txtRight.Text;
                    if (strA == "a" || strA == "b" || strA == "c" || strA == "d")
                    {
                        string s=strA.ToUpper();
                        txtRight.Text.clear;
                        txtRight.Text = s;
                    }            }
      }
      

  5.   

    赞同 cancerser(都是混饭吃,记得要结帖) 
      

  6.   

    有专门的大小写转换函数,不需要搞这么写啊,用 
    txtRight.Text=txtRight.Text.Trim().ToUpper();
      

  7.   

    e.Handled 就是是否执行完原有按键的功能
    =true  原来的按键就不执行了