询问者
WinForm如何把一个窗体接收的事件传递给另一个被隐藏的窗体?

问题
全部回复
-
Hi,
感谢你在MSDN论坛发帖。
你可以先建立一个简单工程,在两个form之间使用委托来传递信息。
下面是我建立的一个工程部分代码,一个form想另外一个form传递字符串。
public delegate void _del(string str); public partial class Form2 : Form { public _del del; public Form2(_del d) { this.del = d; InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { del(richTextBox1.Text); } }
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form2 form2 = new Form2(showstring); form2.Show(); } private void showstring(string str) { label1.Text = str; } }
当form2 点击button,text框中的字符串就会被发送到form1 中。
Best Regards,
Hart
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
- 已建议为答案 Hart WangModerator 2017年3月17日 7:39