首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么实现textBox的backspace连续消除

2012-12-26 
如何实现textBox的backspace连续消除如下图,依次是:textBox1、textBox2、textBox3、textBox4、textBox5 http:/

如何实现textBox的backspace连续消除
如下图,依次是:textBox1、textBox2、textBox3、textBox4、textBox5
 
http://img.my.csdn.net/uploads/201212/19/1355900386_8024.jpg

使用

private void textBox5_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 8)
            {
                this.textBox5.Text = "";
            }
        }


实现了退格键消除textBox的内容,但如何连续呢?
即:消除textBox5以后,继续使用backspace可以消除textBox4,然后可以继续消除textBox3 ......
[解决办法]
你要怎么连续啊。。。想清除某个文本框的内容,总得先把光标移动到控件上吧,楼主是想鼠标都不要动,直接按空格就按顺序清空文本框内容吗?可以这样

private void textBox5_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 8)
            {
                this.textBox5.Text = "";
                textBox4.Focus();//焦点给textBox4
            }            
        }
private void textBox4_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 8)
            {
                this.textBox3.Text = "";
                textBox4.Focus();//焦点给textBox3
            }            
        }
private void textBox3_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 8)
            {
                this.textBox3.Text = "";
                textBox2.Focus();//焦点给textBox2
            }            
        }
private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 8)
            {
                this.textBox3.Text = "";
                textBox1.Focus();//焦点给textBox1


            }            
        }
private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 8)
            {
                this.textBox3.Text = "";
                textBox5.Focus();//焦点给textBox5
            }            
        }

热点排行