用户控件与主窗体间传值
在用户控件中:
.......
public delegate void Message_str(string messageText);
public partial class TEST2 : UserControl
{
public event Message_str Message_Arrived;
public TEST2()
{
InitializeComponent();
this.button1.Click += new EventHandler(button1_Click);
}
void button1_Click(object sender, EventArgs e)
{
Message_Arrived(textBox1.Text);
}
.....
在父窗体中
用户控件.Message_Arrived += new Message_str(t2_Message_Arrived); //引发事件,此代码写在构架函数中
void t2_Message_Arrived(string messageText)
{
this.MAINmsg_lab.Text = messageText; //将传递回的信息显示到MAINmsg_lab中.
}