我如何在Form2中获取变量的值 [英] how i do get a value of variable in form2
本文介绍了我如何在Form2中获取变量的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个形式为1的变量
和一个按钮
我想在单击按钮时将此变量的值从2发送到
.
并以表格2的形式显示给我
以及我如何将表格3设置为开始表格(设置为默认表格)?
i have a variable in form 1
and a button
i want send value of this variable to from 2 when i do click on the button.
and show me in form 2
and how i do set form 3 as start form(set to default)?
推荐答案
您可以通过构造函数将变量从From1传递到Form2.在按钮单击事件中写入以下内容,以将Form1中的TextBox1值传递给Form2中的TextBox1:
Hi,
You can pass variable from From1 to Form2 through constructor. Write following in button click event to pass TextBox1 value in Form1 to TextBox1 in Form2 :
string data = TextBox1.Text;
Form2 obj = new Form2(data);
obj.Show();
In Form2 create a constructor like this:
Form(string data)
{
this.TextBox1.Text = data;
}
class form1
{
type var1;
}
class form2
{
type var2=form1.var1;
}
form1
按钮click_event
form1
Button click_event
string name="Sham";
form2 frm=new form2();
frm.name1=name;
frm.show();this.hide();
form2
表单加载事件
form2
form load event
string name1;
textbox1.text=name1.tostring();
这篇关于我如何在Form2中获取变量的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文