高分请教高手C#Winform问题回答的好再追加分

来源:百度知道 编辑:UC知道 时间:2024/07/06 17:41:15
看图片 有什么办法在我点击添加新商品的时候
弹出新窗体把新窗体的值传过来显示在采购单中
采购单中的行是动态的每添加一次 要增加一行
没明白意思的最好参照美萍的音象管理系统
注意 不是datagridview控件
最好看看美萍的系统

明白是明白 不过我觉得你把程序传过来会更快的给你解答

首先
form1.cs文件中又一个button事件和一个方法。
private void button5_Click(object sender, EventArgs e)
{

Form2 f2 = new Form2();

//第一种方法,把form2的setText事件交给form1的GetText(string text)方法。
f2.T += new Form2.SetText(GetText);
f2.ShowDialog();

//第2中方法把form1的对象传给form2
Form2 ff = new Form2(this);
}

public void GetText(string text)
{
string value = text;
}

然后就是
form2.cs文件
public partial class Form2 : Form
{
//第一种方法就是代理。
public delegate void SetText(string text);
public event SetText T;

Form1 f1 = null;

public Form2()
{
InitializeComponent();
}

//第2中方法
public Form2(Form1 parentForm)
{
this.f1 = parentForm;
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//第2中方法,这里可以调用form1的公开方法和属性,随便你喜欢那一种都可以
f1.GetText(textBox1.Text