标题:求高手指导。异地窗体触发主窗体事件问题
取消只看楼主
shi521min
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-10-8
结帖率:80%
已结贴  问题点数:10 回复次数:1 
求高手指导。异地窗体触发主窗体事件问题
小白我阐述一下我的问题点:点击主窗体按钮弹出一个Form2,然后在form2上点击按钮弹出form3.我想在form3上通过按钮触发主窗体form1的一个事件。如何实现。目前小弟只能做到在form2上可以触发form1的一个事件。求高手指导。代码如下
Form1代码:
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        Form3 bc = null;
        public Form1()
        {
            InitializeComponent();
            bc = new Form3();   
            bc.MyEvent += new Form3.MyDelegate(writeplc);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 a = new Form2();
            a.ShowDialog();
        }

        void writeplc()
        {
            this.textBox1.Text += "已单击b窗体按钮\r\n";
        }
    }
}

Form2代码:

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
       public Form2()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Form3 bd = new Form3();
            bd.ShowDialog();
        }
    }
}

Form3代码:
 namespace WindowsFormsApplication1
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }
        public delegate void MyDelegate();      
        public event MyDelegate MyEvent;
        private void button1_Click(object sender, EventArgs e)
        {
            if (MyEvent != null)
                MyEvent();
        }
        }
    }

搜索更多相关主题的帖子: public null 如何 
2015-05-27 18:26
shi521min
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-10-8
得分:0 
谢谢版指导,已经OK!感谢
2015-05-29 13:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-445846-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034570 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved