|
发表于 2018-8-1 09:58:00
|
显示全部楼层
用委托事件回调。
- // form1.cs
- namespace Main
- {
- public delegate void GetText ( string text ); //定义委托类型
-
- public class form1
- {
- //回调事件
- public event GetText GetFormText;
-
-
-
- private void Button_Click ( object sender, EventArgs e )
- {
- string text = this.TextBox.Text; // 记录文本
- GetFormText?.Invoke(text); // 调用回调
- }
- }
- }
- // fromMain.CS
- namespace Main
- {
- public class fromMain
- {
- private void GetTextFormFrom ( string text)
- {
- // 更新文本;
- this.TextBox.Text = text;
- }
-
- private void Button_Click ( object sender, EventArgs e )
- {
- form1 f1 = new form1();
-
- f1.GetFormText += GetTextFormFrom;
- f1.Show ( );
- }
- }
- }
复制代码 |
|