阅读 110

窗体间的传值-事件

看图了解过程:

 

 

实现:效果

 

 代码展示:fromA

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 UI.test
{
    public partial class FormA : Form
    {
        public FormA()
        {
            InitializeComponent();
        }

        private void FormA_Load(object sender, EventArgs e)
        {

        }
        //A窗体中定义一个可以改变自己文本框内容的方法
        private void SetTXTA(string textBoxB)
        {
            textBoxA.Text = textBoxB;
        }
        //打开窗体B按钮
        private void button1_Click(object sender, EventArgs e)
        {
            FormB fromb = new FormB();
            fromb.Show();
            fromb.SetTXTB_Event += SetTXTA;//为B中的事件绑定A中的方法

        }
    }
}

FormB:

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 UI.test
{
    public partial class FormB : Form
    {
        public FormB()
        {
            InitializeComponent();
        }

        private void FormB_Load(object sender, EventArgs e)
        {

        }
         //委托: Action表示无返回值的委托类型
         //      Funt 表示有返回值的委托类型
        //定义事件
        public event Action<string> SetTXTB_Event;

        private void button1_Click(object sender, EventArgs e)
        {
            //调用事件:
            SetTXTB_Event(textBoxB.Text);

        }
       
    }
}

 

原文:https://www.cnblogs.com/yanghongyan/p/14980476.html

文章分类
代码人生
文章标签
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐