在C#2005中传递表单之间的值 [英] Pass Values between Forms in C# 2005
问题描述
我见过将数据从FormB传递到FormA(Parent To Child)的示例
但我需要一个从FormA到FormB的passind数据示例。我的主要表格是
FormA;我将在文本框中输入一些数据并单击按钮以显示
FormB,它需要显示在FormA中输入的值。
提前感谢。
I have seen examples of passing data from FormB to FormA (Parent To Child)
but I need an example of passind data from FormA to FormB. My main form is
FormA; I will enter some data in textboxes and click a button to bring up
FormB which needs to display values entered in FormA.
Thanks in advance.
推荐答案
6月20日晚上7:28,Rick< R ... @ discussion.microsoft.comwrote:
On Jun 20, 7:28 pm, Rick <R...@discussions.microsoft.comwrote:
我见过将数据从FormB传递到FormA(Parent To Child)的示例
但我需要一个从FormA到FormB的passind数据示例。我的主要表格是
FormA;我将在文本框中输入一些数据并单击按钮以显示
FormB,它需要显示在FormA中输入的值。
提前致谢。
I have seen examples of passing data from FormB to FormA (Parent To Child)
but I need an example of passind data from FormA to FormB. My main form is
FormA; I will enter some data in textboxes and click a button to bring up
FormB which needs to display values entered in FormA.
Thanks in advance.
你想把数据从Parent传递给Child ...对吧???
-Cnu ..
Do you want to pass data from Parent to Child... right???
-Cnu..
<表格A>
FormB b =新FormB(this.TextBox1.Text,this.TextBox2.Text,
this.ComboBox1.SelectedIndex);
b.ShowDialog();
< / FormA>
< ; FormB>
私有字符串_LastName;
私有字符串_FirstName;
private int _PersonTypeID;
public FormB( string LastName,string FirstName,int PersonTypeID):
this()
{
_LastName = LastName;
_FirstName = FirstName;
_PersonTypeID = PersonTypeID;
}
public Form_Load(object sender,EventArgs e)
{
this.txtLastName = _LastName;
this.txtFirstName = _FirstName;
this.cboPersonType.SelectedIndex = PersonTypeID; < br $>
}
< / FormB>
如果你需要重新从FormB中取回值(您正在更改
数据)然后您可以通过
属性添加属性并将其拉出FormA。我在家里的代码中做的是每一个表单控件
有一个已更改的表单控件。被触发的事件,并且通过此事件,新的
值将通过新的EventArg获取。在我的情况下,我想知道
数据是否已被更改,如果是,那么我想更新,但我没有b $ b想要更新它无论如何什么。
<Form A>
FormB b = new FormB(this.TextBox1.Text, this.TextBox2.Text,
this.ComboBox1.SelectedIndex);
b.ShowDialog();
</FormA>
<FormB>
private string _LastName;
private string _FirstName;
private int _PersonTypeID;
public FormB(string LastName, string FirstName, int PersonTypeID) :
this()
{
_LastName = LastName;
_FirstName = FirstName;
_PersonTypeID = PersonTypeID;
}
public Form_Load(object sender, EventArgs e)
{
this.txtLastName = _LastName;
this.txtFirstName = _FirstName;
this.cboPersonType.SelectedIndex = PersonTypeID;
}
</FormB>
If you need to retrieve the values back out of FormB (you''re changing
data) then you can add properties and pull them out in FormA via
properties. What I do in my code at home is every single form control
has a "Changed" event that gets fired and with this event the new
value is taken via a new EventArg. In my case I wanted to know if the
data had been changed and if so then I wanted to update, but I didn''t
want to update it no matter what.
6月20日晚上7:28,Rick< R ... @ discussion.microsoft.comwrote:
On Jun 20, 7:28 pm, Rick <R...@discussions.microsoft.comwrote:
我见过将数据从FormB传递到FormA(Parent To Child)的示例
但我需要一个从FormA到FormB的passind数据示例。我的主要表格是
FormA;我将在文本框中输入一些数据并单击按钮以显示
FormB,它需要显示在FormA中输入的值。
提前致谢。
I have seen examples of passing data from FormB to FormA (Parent To Child)
but I need an example of passind data from FormA to FormB. My main form is
FormA; I will enter some data in textboxes and click a button to bring up
FormB which needs to display values entered in FormA.
Thanks in advance.
请尝试以下代码
公共部分类FormA:表格
{
public FormA()
{
InitializeComponent();
}
private void Form1_Load (对象发送者,EventArgs e)
{
}
private void button1_Click(对象发送者,EventArgs e )
{
FormB formB = new FormB();
formB.data = this.textBox1.Text.ToString( );
formB.Show();
}
}
公共部分类FormB:表格
{
公共字符串数据;
公共FormB()
{
InitializeComponent();
}
private void FormB_Load(object sender,EventArgs e)
{
MessageBox.Show(data);
}
}
Try the following code
public partial class FormA : Form
{
public FormA()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
FormB formB = new FormB();
formB.data = this.textBox1.Text.ToString();
formB.Show();
}
}
public partial class FormB : Form
{
public string data;
public FormB()
{
InitializeComponent();
}
private void FormB_Load(object sender, EventArgs e)
{
MessageBox.Show(data);
}
}
这篇关于在C#2005中传递表单之间的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!