简体   繁体   English

从C#visual studio中的tabPage2访问tabPage1中的textbox1的文本

[英]access text of textbox1 in tabPage1 from tabPage2 in C# visual studio

I am writing my code in Visual Studio 2013 , c# . 我正在用Visual Studio 2013 c#编写代码。 I have a tabControl , it has 2 tabs. 我有一个tabControl,它有2个选项卡。 there is a textbox in tab 1 ! 选项卡1中有一个文本框! I want to copy its text to a label in tab2 ! 我想将其文本复制到tab2的标签中!

how can I do this? 我怎样才能做到这一点?

can it be like : 可以像:

label1.text = tabPage1.TextBox1.text;

I know it cannot be coz there is no TextBox1 when I write tabPage1 . 我知道不可能,因为当我编写tabPage1时没有TextBox1 !

any idea? 任何想法?

I got the answer. 我得到了答案。 All controls of a TabPage are local to a Form and accessible from the Form without adding any additional functionality. TabPage的所有控件都在窗体本地,并且可以从窗体访问而无需添加任何其他功能。 so only this line will work: 因此,仅此行将起作用:

Label1.text = TextBox1.Text; Label1.text = TextBox1.Text;

thank you all 谢谢你们

您正在直接访问标签,为什么不使用文本框也可以这样做?

label1.Text = textBox1.Text;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM