如何在其他TextBox中编写文本并复制相同的文本 [英] How can Write text and copy The Same Text in other TextBox
本文介绍了如何在其他TextBox中编写文本并复制相同的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在TextBox1中写文字
TextBox2 =有相同的文字
例如
TextBox我写12345
TextBox2自动拥有相同Number
解决方案
处理第一个文本框的TextBox.TextChanged事件,并在处理程序中设置第二个文本:
void TextBox1_TextChanged( object sender,EventArgs e)
{
TextBox2.Text = TextBox1.Text;
}
这是一个很好的方法 -
TextBox1。 TextChanged + =(s,_)= >
{
if ( !TextBox2.Focused&& TextBox1.Text!= TextBox2.Text)
{
TextBox2.Text = TextBox1.Text;
}
};
TextBox2.TextChanged + =(s,_)= >
{
if (!TextBox1.Focused&& TextBox2.Text!= TextBox1.Text)
{
TextBox1.Text = TextBox2.Text;
}
};
点击此处查看有关为什么它比其他方法更好的详细说明 -
参考:如何同步两个TextBox控件的文本属性? [ ^ ]
希望,它有助于:)
I Need When I Write text in TextBox1
TextBox2 = have The Same Text
For Example
TextBox I write 12345
TextBox2 Automatic Have The Same Number
解决方案
Handle the TextBox.TextChanged event for the first textbox, and set the text in the second in the handler:
void TextBox1_TextChanged(object sender, EventArgs e) { TextBox2.Text = TextBox1.Text; }
Here is a nice way to do this-
TextBox1.TextChanged += (s, _) => { if (!TextBox2.Focused && TextBox1.Text != TextBox2.Text) { TextBox2.Text = TextBox1.Text; } }; TextBox2.TextChanged += (s, _) => { if (!TextBox1.Focused && TextBox2.Text != TextBox1.Text) { TextBox1.Text = TextBox2.Text; } };
Check here for detailed explanation about why it is better than other methods-
Reference: How can I sync two TextBox control's Text properties?[^]
Hope, it helps :)
这篇关于如何在其他TextBox中编写文本并复制相同的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文