如何将一个文本框的内容复制到其他文本框? [英] How can i copy content of one textbox to other textbox?
本文介绍了如何将一个文本框的内容复制到其他文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
如何在运行时将一个文本框的内容复制到另一个文本框。
解决方案
< blockquote>从评论我可以看到文本框有不同的形式,所以这是形式协作的流行问题。最强大的方法是在表单类中实现适当的接口。
请参阅我之前对这个问题的回答:如何以两种形式复制列表框之间的所有项目 [ ^ ],请参阅其他建议和讨论。
以下是WPF的相同内容:更新不同窗口上的列表视图 [ ^ ]。
您可以实际选择文本,然后在第一个文本框中使用Ctrl + C,然后粘贴你按Ctrl + V进入第二个框。
那么公共类Form1
{
公共字符串TextboxText
{
得到
{
return(textbox1.Text);
}
}
}
公共类Form2
{
private void SomeMethod(Form1 source)
{
textbox1.Text = source.TextboxText;
}
}这假设Form2.SomeMethod()的调用者具有对可用Form1对象的引用。如果不是这样,请提供一个。例如。在Form2的构造函数中。
Hi All,
How can i copy content of one textbox to other at runtime.
解决方案
From comments I can see that the text boxes are in the different forms, so this is a popular question of form collaboration. The most robust way is implementing appropriate interface in the form class.
Please see my past answer to this question: How to copy all the items between listboxes in two forms[^], see other suggestions and the discussion.
Here is the same for WPF: Updating listviews on different windows[^].
—SA
You can actually select text and then use Ctrl+C on the first textbox, and then paste using Ctrl+V into the second box.
So how aboutpublic class Form1 { public string TextboxText { get { return( textbox1.Text ); } } } public class Form2 { private void SomeMethod(Form1 source) { textbox1.Text = source.TextboxText; } }This assumes that the caller of Form2.SomeMethod() has a reference to your Form1 object available. If that is not the case, provide one. E.g. in Form2's constructor.
这篇关于如何将一个文本框的内容复制到其他文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文