如何以另一种形式访问文本框文本 [英] How to access textBox text in another form
问题描述
我有 2 个表单:Form1、Form2
在 Form1
中,我有一个 textBox
,其中包含一些用户必须输入的数据.我需要用户在 Form1 的 textBox
中输入的 text
.如何在 Form2
中访问它?
我使用了 property
但它不起作用,因为用户在运行时输入的文本值.任何机构可以帮助我吗?
I have 2 forms: Form1, Form2
In Form1
I have a textBox
with some data that user have to enter.
I need the text
that the user entered in Form1's textBox
.
How can I access to that in Form2
?
I used property
but it did not work because the text value entered by user in run time.
can any body help me?
推荐答案
为 form2 创建一个接受字符串的构造函数,并在调用 new form2 时将 form1.frm1Textbox.text 传递给构造函数,然后将其设置为 form2.frm2Textbox.text
Make a constructor for form2 that accept string and in calling new form2 pass form1.frm1Textbox.text to contructor then set it to form2.frm2Textbox.text
Form2 form = new Form2(frm1Textbox.text);
在form2构造函数中
in form2 constructor
public class Form2 : Form
{
public Form2(string text)
{
frm2Textbox.Text = text;
}
}
这篇关于如何以另一种形式访问文本框文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!