如何将值从表单1传递到表单2 [英] How to pass value from form 1 to form 2
本文介绍了如何将值从表单1传递到表单2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从form1更新form2的texbox。
在form2中我有一个显示结果形式mysql数据库的文本框我需要从form1设置值。
方法是什么。请帮助。
谢谢你
Hi,
I want to update a texbox of form2 from form1.
In form2 i have a textbox which show result form mysql database i need to set value from form1.
What is the method. Please help.
Thank You
推荐答案
这取决于表单之间的关系:哪一个是另一个的父级,依此类推。
其中一个应该涵盖它:
在两种形式之间转移信息,第1部分:父母对儿童 [ ^ ]
在两种表格之间转移信息,第2部分:儿童到家长 [ ^ ]
Transferr两种表格之间的信息,第3部分:儿童与儿童 [ ^ ]
It depends on the relationship between the forms: which is the parent of the other and so forth.
One of these should cover it:
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
让我们看一个例子,我假设你的表格1的值是string
然后,为 form2 创建一个接受该字符串值的构造函数,并在调用new form2 时将该值传递给构造函数,然后将其设置为 form2 .frm2Textbox.text 喜欢:
Let see an example, I assume your value of form 1 isstring
then, make a constructor for form2 that accept that string value and in calling new form2 pass that value to constructor then set it to form2.frm2Textbox.text like :
Form2 form = new Form2(valueOfForm1);
在form2构造函数中:
In form2 constructor:
public class Form2 : Form
{
public Form2(string text)
{
frm2Textbox.Text = text;
}
}
您可以传递上述示例中的任何类型的值。还会混淆吗?请参阅:
在两个表单之间传递数据(使用c#的Windows表单) [ ^ ]
你好!
如果你想在窗体中找到这个,请参考此链接
http://stackoverflow.com / questions / 11165537 / passing-textboxs-text-to-another-form-in-c [ ^ ]
Ravi Halvadiya
软件工程师
电子邮件:ravi@insightsoftech.com
>
这篇关于如何将值从表单1传递到表单2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文