zoukankan      html  css  js  c++  java
  • 委托初探

    理解委托:关于两个窗体的互操作

    Form1:

        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void frm_setTextEvent(string text)
            {
                this.Text = text;
            }

            private void button1_Click(object sender, EventArgs e)
            {
                Form2 frm = new Form2();
                frm.setTextEvent += new Form2.setTextHandler(frm_setTextEvent);
                frm.Show();
            }
        }

    Form2:

        public partial class Form2 : Form
        {
            public delegate void setTextHandler(string text);
            public event setTextHandler setTextEvent;

            public Form2()
            {
                InitializeComponent();
                this.button1.Click += new EventHandler(button1_Click);
            }

            private void button1_Click(object sender, EventArgs e)
            {
                if (setTextEvent != null)
                {
                    setTextEvent("yourtext");
                }
            }
        }

  • 相关阅读:
    如何使用Log4j
    HDU 1114
    老鼠与毒药问题
    HDU 1065
    HDU 1301(MST)
    HDU 1078
    HDU 2159
    删除字符问题(贪心)
    正整数分解为几个连续自然数之和
    OpenJudge
  • 原文地址:https://www.cnblogs.com/2008freestyle/p/1857148.html
Copyright © 2011-2022 走看看