当我删除textbox1中的数据时,如何删除textbox2中的数据 [英] How to delete data in textbox2 when I delete data in textbox1

查看:88
本文介绍了当我删除textbox1中的数据时,如何删除textbox2中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本框

textbox1

textbox2



我在textbox1中输入文字显示在另一个文本框



问题是当我在textbox1上按退格键时它应该在textbox2中删除



但当我按退格键时,textbox2中的全部内容消失了



我尝试过的事情:



private void textBox1_KeyPress(object sender,KeyPressEventArgs e)

{

string s =;

if(char。 IsLetterOrDigit(e.KeyChar))

{

s + = e.KeyChar.ToString();

textBox2.Text = s;





}



}

i have two textboxes
textbox1
textbox2

where i enter text in textbox1 is displayed in another textbox

the problem is when i press backspace on textbox1 it should delete as well in textbox2

but when i press backspace whole content in textbox2 is vanish

What I have tried:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
string s = "";
if (char.IsLetterOrDigit(e.KeyChar))
{
s += e.KeyChar.ToString();
textBox2.Text = s;


}

}

推荐答案

为什么这样做?

你可以使用Textbox1中的TextChanged-Event来分配Textbox1 .Text到TextBox2.Text ...
Why do you do it like this ?
You could use the TextChanged-Event from Textbox1 to assign the Textbox1.Text to TextBox2.Text ...


在我的个人推荐(和意见)中,我建议你使用数据绑定并将数据绑定到彼此。这样,框架将处理这两个字段的值,并在用户对其中一个字段进行更改时更新和删除值。



Web窗体控件可以相互绑定,框架可以控制其余部分。这种方法的好处(如果是双向的)是您将能够在它们中共享相同的文本。其中一个的变化也会反映在另一个变化中。



如需更多信息,请阅读:

Web窗体页面中的数据绑定简介 [ ^ ]

Web窗体页面的数据绑定表达式 [ ^ ]
In my personal recommendation (and opinion), I will recommend that you use data binding and bind the data to each other. This way, framework would handle the values of both of these fields and would update and remove the values when user makes a change in one of them.

Web Forms controls can be bound to each other and the framework would take the control over the rest. The benefit of this approach (if two-way) is that you will be able to share the same text in both of them. A change in one of them would be reflected in the other one too.

For more, please read:
Introduction to Data Binding in Web Forms Pages[^]
Data-Binding Expressions for Web Forms Pages[^]


最后我做到了



这是解决方案兄弟





Finally i have done it

Here is the solution brother


private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            textBox2.Text = textBox1.Text;
        }


这篇关于当我删除textbox1中的数据时,如何删除textbox2中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆