通过委托实现窗体间通信
通过委托实现窗体间通信using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Form1DelegateForm2 { /// ///主窗体/// public partial class Form1 : Form { public Form1() { InitializeComponent(); textBox1.Text = "演示文本"; } private void button1_Click(object sender, EventArgs e) { Form2 frm = new Form2(this.textBox1.Text); frm.myEvent += this.ModifyText; frm.ShowDialog(); } /// ///让子窗体中的委托来调用/// /// public void ModifyText(string s) { this.textBox1.Text = s; } } }
29.98KB
文件大小:
评论区