具体不明白你的意思,,,不晓得 是不是 在form2中的textbox中添加值,然后form1中的combox1中的下拉选型就自动添加对对应的值,我尝试做了个demo,发给你作参考.....
直接贴代码了:
mainForm
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
}
}
}
form2:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
Init();
}
private void Init()
{
Form3 f3 = new Form3();
f3.Show();
f3.handler += new MyEventHandler(f3_handler);
}
void f3_handler(object sender, MyEventArgs e)
{
this.comboBox1.Items.Add(e.Text.ToString());
}
}
}
form3:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication
{
public delegate void MyEventHandler(object sender,MyEventArgs e);
public partial class Form3 : Form
{
public event MyEventHandler handler;
public Form3()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
MyEventArgs myEvent = new MyEventArgs();
myEvent.Text = this.textBox1.Text;
if (handler != null)
{
handler(this, myEvent);
}
}
}
}
在定义一个事件类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication
{
public class MyEventArgs:EventArgs
{
public string Text
{
get;
set;
}
}
}
追问你好,辛苦了,看你的代码好像是用委托来传递参数的,如果form3和form2都是form1的成员呢,你的form3好像是在form2中初始化的,要是平级的呢就是没有父子关系怎么做啊。另外你可以帮我解答下我的追问里的疑问么,谢谢了,我是初学者,详细点哈~~~谢谢啊
本回答被提问者采纳